AlgoUniversity
  • Go Back
Discussion
String Reversal :

Author

Akash

Difficulty Level : Easy

Submissions : 1241

Asked In : deshaw

Marks :10

: 18 | : 1

A series of $$$num$$$_$$$operations$$$ are performed on a string $$$initial$$$_$$$string$$$ of length $$$n$$$ that contains lowercase English letters only. In the $$$i$$$th operation, the prefix of the string of length $$$i$$$ is reversed. The final string thus formed is represented by $$$final$$$_$$$string$$$.

Given the string $$$final$$$_$$$string$$$ and an integer $$$num$$$_$$$operations$$$, find the initial string on which the operations were performed.

$$$\bf Example:$$$

Suppose $$$final$$$_$$$string$$$ = "chakerrank" and $$$num$$$_$$$operations$$$ = 3.

Then the initial string will be "hackerrank".

On the first operation, reverse "h" -> "hackerrank"

On the second operation, reverse "ha" -> "ahckerrank"

On the third operation,Reverse "ahc" -> "chakerrank" which is equal to $$$final$$$_$$$string$$$.

Input

The first line contains the final string $$$S$$$ $$$(1 \le |S| \le 10^5)$$$.

The second line contains an integer $$$num$$$_$$$operations$$$ $$$(1 \le m \le |S|)$$$ denoting the number of operations.

Output

Return the initial string.

Examples

Input
chakerrank
3
Output
hackerrank
Input
bbaaaba
5
Output
aababba

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.