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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Medium

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
linked list
position partitioning
in-place relinking
two pointers
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported