Marks :10
: 17 | : 0
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$$$.
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.
Return the initial string.
chakerrank 3
hackerrank
bbaaaba 5
aababba
You need to login to view your submissions.
You need to login to view all submissions.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.