Return the Later Middle Node of a Singly Linked List

Quick Overview

Return the Later Middle Node of a Singly Linked List. Return the middle node pointer of the singly linked list beginning at head.

Return the Later Middle Node of a Singly Linked List

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return the middle node pointer of the singly linked list beginning at `head`. If the list has two middle nodes, return the second one. Example output lists show the suffix beginning at the returned existing node; the function does not return a new array or copied list. ```cpp class Solution { public: ListNode* middleNode(ListNode* head); }; ``` ### Examples **Example 1:** ```text Input: head = [8,2,9] Output: node with value2, suffix[2,9] Explanation: The middle is the second node, whose value is2. ``` **Example 2:** ```text Input: head = [6,1,4,7] Output: node with value4, suffix[4,7] Explanation: The two middle positions are2 and3; choose position3. ``` ### Constraints - The list contains1 to100 nodes. - `1 <= Node.val <= 100`. ### Contract considerations The list is nonempty, so the returned pointer exists. The native ListNode interface and supplied type definition remain unchanged. ```hint Read the boundary condition Compare where a two-step pointer stops for odd and even list lengths. ``` ### Boundary reminders The list is nonempty, so the returned pointer exists. The native ListNode interface and supplied type definition remain unchanged.

Overview: Return the Later Middle Node of a Singly Linked List. Return the middle node pointer of the singly linked list beginning at head.

Google logo
Google
Sep 2, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return the middle node pointer of the singly linked list beginning at head. If the list has two middle nodes, return the second one. Example output lists show the suffix beginning at the returned existing node; the function does not return a new array or copied list.

class Solution {
public:
    ListNode* middleNode(ListNode* head);
};

Examples

Example 1:

Input: head = [8,2,9]
Output: node with value2, suffix[2,9]
Explanation: The middle is the second node, whose value is2.

Example 2:

Input: head = [6,1,4,7]
Output: node with value4, suffix[4,7]
Explanation: The two middle positions are2 and3; choose position3.

Constraints

  • The list contains1 to100 nodes.
  • 1 <= Node.val <= 100 .

Contract considerations

The list is nonempty, so the returned pointer exists. The native ListNode interface and supplied type definition remain unchanged.

Boundary reminders

The list is nonempty, so the returned pointer exists. The native ListNode interface and supplied type definition remain unchanged.