Display and Manipulate Linked List
Filed under Cisco
Free read 3 of 3Confirm definition of middle node for even-length lists (usually second middle).
The question
Perform standard operations on a singly linked list including displaying all elements, finding the middle node, and reversing the linked list.
Constraints
- 0 <= number of nodes <= 5000
- -10^4 <= node.val <= 10^4
Examples
- Input
- head = [1, 2, 3, 4, 5]
- Output
- Reversed: [5, 4, 3, 2, 1], Middle: 3
- Why
- Standard linked list utilities demonstrated on an odd-length list.
Approach
Confirm definition of middle node for even-length lists (usually second middle).
Traverse from head to end printing or collecting node values into a list.
Use slow and fast pointer approach where fast moves 2 steps and slow moves 1 step.
Iterate using prev, curr, and next pointers to reverse direction of pointers in-place.
Tips
- What they are testing: Test with empty list, single node list, even number of nodes (for middle node behavior), and odd number of nodes.
- Common mistake: Losing reference to the rest of the list when reversing or handling pointer updates.
Related Cisco questions
Collected from public candidate posts and coding forums. Updated Nov 2026.