Group Odd-Position Map Tiles Before Even-Position Ones
Last updated: November 29, 2026
Quick Overview
A singly linked list of map tile IDs should be reordered so all nodes at odd positions (1st, 3rd, 5th, ...) come first, followed by all nodes at even positions, each group in original order, using O(1) extra space.
0
0
0 solved
A singly linked list of map tile IDs should be reordered so all nodes at odd positions (1st, 3rd, 5th, ...) come first, followed by all nodes at even positions, each group in original order, using O(1) extra space.
A Google phone screen problem about position-based partitioning, framed around prefetching alternate Maps tiles. The interviewer checks that you split by position, not value, and that the loop condition avoids None dereferences.
What the Interviewer Expects
- Split by position, not by tile value
- Maintain odd and even tails while walking
- Remember the head of the even list to reattach
- Use a loop condition that covers odd and even lengths
- O(n) time, O(1) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Group by position modulo 3.
- Do it by value parity instead and keep stability.
- Reverse the even group before attaching.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: head of a singly linked list.
- Output: head of the list with odd-position nodes first, then even-position nodes.
- Relative order within each group preserved; O(1) space....
High-Level Design
Keep two chains that grow as we walk: odd starts at the head and even starts at head.next; also save even_head. On each iteration the next odd node is even.next, so link odd.next = even.next...