A habit-building app for algorithms and data structures.
Interviews still ask DSA questions. knute makes practicing them a few minutes a day on your iPhone.
You're on the list.
We'll email you when invites open.
Thanks for helping shape Knute.
Interviews still ask DSA questions. knute makes practicing them a few minutes a day on your iPhone.
We'll email you when invites open.
Thanks for helping shape Knute.
Reverse an array in place with two pointers.
Swap the two ends. Move both pointers inward. Stop when they meet.
Place left and right where the reversal starts.

Locked in! left starts at index 0 and right at index 5.
One swap is done. What does the next swap give?

Locked in! 3 and 9 trade places.
Finish the loop.
def reverse(nums):
left = 0
right = len(nums) - 1
while ______left < right:
nums[left], nums[right] = (
nums[right], nums[left])
______left += 1
______right -= 1

Locked in! left < right stops the loop in the middle.
How does the time grow with the length of nums?

Locked in! n / 2 swaps is still O(n).
Lesson complete!
Reverse an array in place
[2, 9, 1, 8, 3, 5]

