word of lowercase English letters and an integer reach. In one move you may take any one of the first reach letters, cut it out and append it to the end of the string.
You may make as many moves as you like, including none. Return the lexicographically smallest string you can end up with.word="dbca", reach=1 → 'adbc'
Only the first letter can move, which gives the rotations dbca, bcad, cadb and adbc. The smallest is adbc.
word="dbca", reach=2 → 'abcd'
Choosing between the first two letters lets you reach any arrangement, including the letters in sorted order.
word="zz", reach=1 → 'zz'
reach ≤ len(word) ≤ 1000word consists of lowercase English lettersword="dbca", reach=1
'adbc'
Run checks the first 3 tests in your browser. Submit checks all 119 tests on the server, hidden ones included.