This question is very poorly worded. The point is that you reverse from 0 until k characters, then ignore the next k characters, then after that reverse the next k characters, and so on. So in the above example with k = 2:
ab cd ef g
ba cd fe g
If you are reversing and have fewer than k characters left to reverse, then you reverse them all.
My approach was to take the standard in place “two pointer” array reversal technique, then pass that substrings (via begin and end indices). The driving function then looks like:
And the actual array reversing function is fairly standard:
You can also use an alternative “driver function” were you increment your loop in steps of k and alternate:
Both were faster than ~70% of submissions: