Dsa
Linked List
Medium
The Centroid Zip
Given a linked list of integers, find the 'centroid' node. The centroid is the node where the absolute difference between the sum of all elements to its left (inclusive) and the sum of all elements to its right (exclusive) is minimized. If multiple nodes satisfy this, choose the one closest to the head. Split the list into two after this centroid node. Reverse the second list, then merge the two lists by alternating nodes starting with the first list. If one list is longer, append the remaining nodes to the end.
Example:
Input: 1 2 3 4 5
- Split at 3: (1+2+3)=6 vs (4+5)=9. Diff 3. (Best choice)
- Lists: [1, 2, 3], [4, 5]
- Reverse second: [5, 4]
- Zip: 1 -> 5 -> 2 -> 4 -> 3
Output: 1 5 2 4 3
Key concepts
linked_listtwo_pointersreversal
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now