Middle of a Linked List
Updated
Problem statement
Return the middle node of a singly linked list. If its length is even, return the second of its two middle nodes. Return null for an empty list, and do not change any next pointer.
Lists are shown as arrays of node values. The returned node is shown as the values from that node through the end of the list. An empty array represents null.
Function
middleNode(head: ListNode) → ListNodeExamples
Example 1
head = [1,2,3,4,5]return = [3,4,5]The list has five nodes. The third node is in the middle, with two nodes on each side. Return it, so the output shows the list from that node to the end.
Example 2
head = [1,2,3,4,5,6]return = [4,5,6]The list has six nodes, so it has two middle nodes: the third and the fourth. The rule picks the second of them, the fourth node. The output shows the list from that node to the end.
Example 3
head = []return = []The list is empty, so there is no middle node. Return null, which is shown as an empty array.
Constraints
- The list has no cycle, so it always ends. It contains between
0and10^5nodes. -10^9 <= node.val <= 10^9.
More Apple Onsite Interview questions
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- FIFO Mutex Operation TraceONSITE INTERVIEW · Seen Oct 2026
- Implement Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Parse Nested HTML into a TreeONSITE INTERVIEW · Seen Oct 2026
- Thread-Safe Concurrent Linked ListONSITE INTERVIEW · Seen Sep 2026
- Palindrome Match PercentageONSITE INTERVIEW · Seen Sep 2026
- Binary Tree Nodes at Distance KONSITE INTERVIEW · Seen Aug 2026
- BST to Sorted Circular Doubly Linked ListONSITE INTERVIEW · Seen Aug 2026
Similar questions at other companies
- Merge Two Sorted ListsLinkedIn · PHONE SCREENLinkedIn interview questions
- Middle of a Linked ListCisco · PHONE SCREENCisco interview questions
- Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
- Merge Two Sorted ListsIBM · PHONE SCREENIBM 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
- Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
- Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Build and Check a Palindrome Linked ListOmnissa · ONSITE INTERVIEWOmnissa interview questions