FastPrepMiddle of a Linked List
Problems/Middle of a Linked List

Middle of a Linked List

Apple logoApple● EasyNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The middle-node task, second-middle rule, and empty-list result match the source at about 98%. Finite bounds complete the practice inputs; the source's insertion remark is not part of the linked task.

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) → ListNode

Examples

Example 1

head = [1,2,3,4,5]return = [3,4,5]
head
12345
Removed
→
return
345
Moved or new

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]
head
123456
Removed
→
return
456
Moved or new

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 = []
head
empty
return
empty

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 0 and 10^5 nodes.
  • -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

Interview reports that mention this question

  • Apple India SWE New Grad Interviews: 5 Experiences

Apple interview experiences

  • Apple SWE Phone Screen: Subarray Products: 1 Experience
  • Apple New Grad SWE Java, Coding and Manager Rounds: 1 Experience
  • Apple AI Coding and Related Interviews: 17 Experiences
  • Apple New Grad SWE Phone Screens: 12 Experiences (Part 3 of 3)
  • Apple New Grad SWE and Embedded: 16 Experiences (Part 2 of 3)
All Apple interview questionsSee Apple hiring insights
Saved
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode middleNode(ListNode head) {
        // Write your solution here.
    }

}
Checking account…