Odd Even Linked List
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given the head of a singly linked list, regroup its nodes by **position**: all nodes at odd positions (1st, 3rd, 5th, ...) come first, followed by all nodes at even positions (2nd, 4th, ...). Positions are counted from 1 and have nothing to do with the node values.
Within each group, keep the nodes in the order they originally appeared. Return the head of the regrouped list.
Solve it by relinking nodes in a single pass with O(1) extra space.
Examples
Constraints
- 0 <= number of nodes <= 10^4
- -10^6 <= Node.val <= 10^6
- Positions are counted from 1; values may repeat and do not affect grouping
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.