Two-Pointer Swap
"hello world" → "dlrow olleh" · two markers trade places until they meet
The Word, Live
Custom Word:
Step by Step
Step 1 / 9
The Code Behind It
reverse_array.py
In plain English:
Theory & Fundamentals
The Two-Pointer Technique
Reversing an array or string in-place is a fundamental concept frequently tested in exams. By using a Left and Right pointer and swapping elements directly, we achieve O(1) auxiliary space (no extra memory) and O(N) time complexity (linear time).
Knowledge Check
Q1: Tracing the Algorithm
If the starting word is "EXAMS", what will the string look like after exactly 1 swap?
Q2: Loop Condition
Why does the while loop use the condition l < r instead of l <= r?
Q3: Space Complexity
What is the auxiliary space complexity of reversing a string in-place using two pointers?