Trace a list reversal
Standard · Trace the algorithm · about 6 min
Follow the reversal of 1 → 2 → 3 → 4 with prev, cur and nxt. Answer each question before the step plays.
Example 1
Input:
{"values":[1,2,3,4]}
Output:
[4,3,2,1]
Constraints
- The trace uses the list shown.
Learn the idea first: Linked list techniques: reverse, middle, merge, detect a cycle, a visual lesson.
More Linked list techniques: reverse, middle, merge, detect a cycle problems
- Reverse a list Warm-up
- Middle node Warm-up
- Merge two sorted lists Standard
- Palindrome list Standard
- Find the cycle start Challenge