← Arrays & Pointer Arithmetic

Reverse In Place

hard

Implement reverse to reverse the array in place – modify arr through its pointer directly, without allocating a second array to copy into.

The standard technique is two indices (or, equivalently, two pointers) starting at opposite ends and walking toward each other, swapping as they go, stopping once they meet or cross. This “converge from both ends” pattern shows up again for palindrome checks, partitioning, and quicksort – worth having solid here. Trace it by hand on a 4-element and a 5-element array before coding: does your stopping condition (left < right) correctly leave a lone middle element alone in the odd case?

Your solution

"Run" uses the sample stdin ("5\n1 2 3 4 5"). "Submit" checks your code against all 4 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution