Lexicographical Challenge
InterviewTime limit0.5sMemory limit1024 MB
Given a string S and an integer K, find the lexicographically smallest string reachable by swapping S_i with S_(i+K) any number of times.
- Level
Easy3 of 10
- Topics
- String, Sorting, Implementation
- Solved
- No attempts yet
Problem
In the village of Lexicoville, Lily and Ethan received a mysterious letter containing a riddle. The riddle gives an integer and a string made only of lowercase letters. At any moment, the villagers may choose an index and swap the characters and . Using only this operation, find the lexicographically smallest string that can be obtained.
Input
The first line contains the string (). The second line contains the integer ().
Output
Output a single line with the lexicographically smallest string that can be obtained.