Dsa
Linked List
Easy
Sparse Vector Addition
Large vectors are often stored as linked lists of (index, value) pairs to save space, keeping only non-zero entries. Given two such linked lists (sorted by index), add them together. If an index exists in both, sum their values. If the sum is zero, remove the node. The result must be sorted by index.
Input:
1. A line of 'index:value' pairs for Vector A.
2. A line of 'index:value' pairs for Vector B.
Output:
Space-separated 'index:value' pairs of the resulting vector.
Example:
Input:
0:5 3:10 5:2
2:4 3:-10 5:8
Output:
0:5 2:4 5:10
Key concepts
linked_listcoordinate_listmathematical_simulation
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