Smallest After Moving Letters
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
1 <= k <= len(s) <= 60shas lowercase letters only
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Strings problems
- Smallest Order Without TwinsHard
- Acronym of WordsBeginner
- Alternating CaseBeginner
- Capitalize the TitleBeginner
- Center in a FieldBeginner
- Chunks From the LeftBeginner
- Consecutive CharactersBeginner
- Count Capitalized WordsBeginner