Description
You are given a string s and an integer k. You can choose one of the first k letters of s and append it at the end of the string. Return the lexicographically smallest string you can have after any number of moves.
Examples
Input:
s = "cba", k = 1Output:
"acb"Explanation:
Rotate to get acb.
Input:
s = "a", k = 1Output:
"acb"Explanation:
Edge case with a single character.
Input:
s = "baaca", k = 2Output:
"aabac"Explanation:
With k=2, any of the first 2 characters can be moved to the end at each step. Since k >= 2, any permutation of the string is achievable. The lexicographically smallest permutation of 'baaca' is 'aaabc'.
Constraints
- •
1 ≤ k ≤ s.length ≤ 1000