Imagine you have a queue of characters from a string, and you're allowed to make strategic moves to rearrange them. You are given a string s and an integer k. In each move, you can choose one of the first k characters from the current string and move it to the end.
Your goal is to find the lexicographically smallest string possible after performing any number of these moves. Think of it as optimizing a queue where you have limited access to only the first k positions!
Example: If s = "cba" and k = 1, you can only move the first character to the end. Starting with "cba" → "bac" → "acb" → "cba" (cycle), the smallest possible is "acb".
However, if k ≥ 2, you gain much more flexibility and can potentially achieve any permutation of the characters!
Input & Output
Constraints
- 1 ≤ s.length ≤ 1000
- 1 ≤ k ≤ s.length
- s consists of lowercase English letters only