Drawn and Quartered
InterviewTime limit2sMemory limit512 MB
A fixed permutation is applied to a string K times; find where each index goes and output the rearranged string.
- Level
Medium6 of 10
- Topics
- Math, Bit manipulation, Recursion
- Solved
- No attempts yet
Problem
You are playing a game that involves drawing and redrawing a string on a blackboard. You start with a string of length and perform a switcheroo on the string exactly times. A switcheroo involves breaking into quarters, and then moving the middle two quarters to the end of without changing their relative order to each other. For example, say you start with aabbccdd. After a single switcheroo, the string becomes aaddbbcc. After another switcheroo, you have aaccddbb, and so on.
Given a starting string and the number of times you should perform a switcheroo, what is the final state of the string?
Input
The input starts with a line containing two integers (), the length of the string, and (), the number of times you should perform a switcheroo on . It is guaranteed that is a multiple of 4.
The second line contains . The string contains only lowercase letters and consists of exactly characters.
Output
Display the string after performing switcheroos.