Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Orderly Queue

XPChallenge Points: 30
levelLevel: Hard

You are given a string s and a number k.
In each move, you may pick any character from the first k positions of the string and place it at the end of the string.

You can repeat this operation as many times as you want.

Your task is to determine the smallest possible string in lexicographical order that can be formed after performing these moves any number of times.

Example 1:

Input: s = "dbca", k = 1

Output: "acbd"

Explanation:

Only rotations are allowed. The rotation "acbd" is the smallest among all rotations.

Example 2:

Input: s = "zzxy", k = 2

Output: "xyzZ"

Explanation:

Because k > 1, we can freely rearrange characters. Sorted order gives the smallest string.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result