#C7490. Reverse String II
Reverse String II
Reverse String II
You are given a string \(s\) and an integer \(k\). The task is to reverse the first \(k\) characters for every consecutive block of \(2k\) characters in \(s\).
If there are fewer than \(k\) characters left, reverse all of them. If there are at least \(k\) but less than \(2k\) characters remaining, then reverse the first \(k\) characters and leave the rest unchanged.
For example, if \(s = \texttt{abcdefg}\) and \(k = 2\), the output is \(\texttt{bacdfeg}\).
inputFormat
The input consists of two lines:
- The first line contains the string \(s\).
- The second line contains the integer \(k\).
outputFormat
Output the string after performing the required reversal operations on every \(2k\) block.
## sampleabcdefg
2
bacdfeg