FunctionRacerProblemsRace

Smallest After Moving Letters

HardStringsPython, JavaScript, TypeScript, Java, C++

One move takes one of the first k letters of the string and puts it at the end. You may make as many moves as you like. Return the alphabetically smallest string you can reach from s.

Example 1

s "cba"
k 1
returns "acb"

Only the first letter can move: "cba" turns into "bac" and then "acb". None of the three beats "acb".

Example 2

s "baaca"
k 3
returns "aaabc"

With k = 3 the letters can be put in any order.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems