Swapping Game
Practice
3.3 (31 votes)
Ad Hoc
Approved
Data structures
Medium
Open
Problem
71% Success 7748 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string.
One swap on a string is performed in this way:

  • Assuming 1 indexing, the i'th letter from the end is inserted between i'th and (i+1)'th letter from the starting.

For example, we have "contest". After one swap, it would change to "ctosnet". Check this image:

enter image description here

Input:
First line contains K, the number of swaps performed by Watson. Next line contains S, the string Watson gives to Sherlock.

Output:
You have to print in one line the original string with which Watson had started.

Constraints:
1 ≤ K ≤ 109
3 ≤ Length(S) ≤ 1000
All characters in S will be small English alphabets.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
7 votes
Tags:
AlgorithmsBasics of String ManipulationString Algorithms
Points:30
27 votes
Tags:
Medium
Points:30
6 votes
Tags:
AlgorithmsString AlgorithmsBasics of String ManipulationStringData Structures