text and a number k. Cut the string from left to right into blocks of k characters; the last block may be shorter.
Reverse the first block, the third, the fifth and so on, that is, every odd-numbered block when counting from one. Leave the even-numbered blocks as they are. Return the resulting string.text='abcdefghij', k=3 → 'cbadefihgj'
Blocks of 3: abc, def, ghi, j. The first and third are reversed: cba + def + ihg + j. The last block j is the fourth one, so it stays.
text='window', k=4 → 'dniwow'
The first block wind becomes dniw, and the second, short block ow stays: dniwow.
text='sky', k=5 → 'yks'
The whole string is shorter than k, so it is the first block and gets reversed: yks.
text.length ≤ 10⁴text consists of lowercase English lettersk ≤ 10⁴text='abcdefghij', k=3
'cbadefihgj'
Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.