Remove Even-Positioned Linked-List Nodes
Updated
Problem statement
Given the head of a finite, acyclic singly linked list, remove every node whose one-based position in the original list is even and return the resulting head.
Keep the nodes originally at positions 1, 3, 5, ... in their original relative order. Relink the existing nodes; do not change any node value. The input list may be empty, in which case return an empty list.
Function
removeEvenPositionedNodes(head: ListNode) → ListNodeExamples
Example 1
head = [1,2,3,4,5]return = [1,3,5]Removed
Moved or new
The nodes originally at positions 2 and 4 are removed.
Example 2
head = [7,8]return = [7]Removed
The second node is in an even position, so only the first node remains.
Example 3
head = []return = []An empty list remains empty.
Constraints
0 <= number of nodes <= 100000.- Every node value fits a signed 32-bit integer.
- The input list is finite and contains no cycle.
- Reuse the existing nodes and use
O(1)auxiliary space.
More Oracle Phone Screen questions
- Remove Parentheses from a Plus-Minus ExpressionPHONE SCREEN · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · Seen Oct 2026
- Shortest Window by Distinct-Value SumPHONE SCREEN · Seen Oct 2026
- Detect a Cycle in a Directed GraphPHONE SCREEN · Seen Oct 2026
- Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Remove Adjacent Duplicates in String IIPHONE SCREEN · Seen Oct 2026
- Sum Root-to-Leaf Binary NumbersPHONE SCREEN · Seen Oct 2026
- Longest All-Present Attendance StreakPHONE SCREEN · Seen Oct 2026
- Next PermutationPHONE SCREEN · Seen Sep 2026
- Valid ParenthesesPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Reverse Linked ListByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Merge Two Sorted ListsLinkedIn · PHONE SCREENLinkedIn interview questions
- Middle of a Linked ListCisco · PHONE SCREENCisco interview questions
- Reverse a Linked ListApple · PHONE SCREENApple interview questions
- Merge Two Sorted ListsIBM · PHONE SCREENIBM interview questions
- Reverse a Singly Linked ListChubb · PHONE SCREENChubb interview questions
- Remove All Repeated Values from a Linked ListArista Networks · PHONE SCREENArista Networks interview questions
- Detect a Cycle in a Linked ListSalesforce · PHONE SCREENSalesforce interview questions
- Find the Intersection Node of Two Linked ListsVisa · PHONE SCREENVisa interview questions
- Reverse a Linked ListMygate · PHONE SCREENMygate interview questions