Dsa
Linked List
Medium
Look-and-Say Consolidation
Traverse a linked list and identify consecutive runs of the same value. Replace each run with two nodes: the value and the length of the run. The order of these two nodes depends on the length: if the length is even, the length node must come BEFORE the value node. If the length is odd, the length node must come AFTER the value node.
Example:
Input: 2 2 2 3 3 1
- Run 1: Value 2, Length 3 (odd) -> 2 3
- Run 2: Value 3, Length 2 (even) -> 2 3
- Run 3: Value 1, Length 1 (odd) -> 1 1
Output: 2 3 2 3 1 1
Key concepts
linked_listrun-length encodingtransformation
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