482. Reverse String II
EasyString
For every block of 2k characters, reverse the first k. If fewer than k remain, reverse them all; if between k and 2k remain, reverse the first k.
Input format
Line 1: s Line 2: k
Output format
The transformed string.
Example 1
Input
abcdefg 2
Output
bacdfeg
Example 2
Input
abcd 2
Output
bacd
Constraints
1 ≤ |s| ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…