Reverse Every Other Chunk
Split S into blocks of 2K; in each block reverse the FIRST K characters and keep the next K as they are (short tails: reverse what exists of the first K).
Input: the first line has S; the second line has K.
Output: the transformed string.
Constraints:
- 1 ≤ |S| ≤ 104
- 1 ≤ K ≤ |S|
Sample Tests
Input 1
abcdefg 2
Output 1
bacdfeg
Input 2
abcd 4
Output 2
dcba
Discussion (opens after you solve — no spoilers before)
No comments yet.