As reported: Akamai Software Engineer II (Backend, India remote) interview on HackerRank (2025): one coding question — given a linked list, return a new linked list containing only the odd numbers (e.g.
1 → 2 → 3 → 4 → 5 → 6 → 7 → 8gives1 → 3 → 5 → 7), with time and space complexity, then follow-ups about circular linked lists and variants. The rest of the round covered security, concurrency and database concepts.
Given the head of a singly linked list of integers, return the head of a new linked list that contains only the nodes whose values are odd, in their original order. The input list must not be modified.
Example 1
head = [1,2,3,4,5,6,7,8]
Output: [1,3,5,7]
Example 2
head = [2,4,6]
Output: []
Example 3
head = [-3,10,7,-8,9]
Output: [-3,7,9]
Constraints: 0 ≤ number of nodes ≤ 10^5; -10^5 ≤ Node.val ≤ 10^5. A negative number is odd when it is not divisible by 2.
Follow-ups
- What changes if the list is circular?
Code runner format: one JSON line: the list as an array. Implement oddList(head) returning the new list's head; the runner prints it as an array and also checks that the input list was left unchanged.