Skip to main content

Midpoint Node Finder

easy
Linked ListTwo PointersFast Slow Pointers
Asked atAmazonMicrosoftAppleBloomberg

Problem Description

Given the head of a singly linked list, return the middle node of the list.

If the list has an even number of nodes, return the **second** of the two middle nodes.

**Example 1:**
```
Input: head = [4, 8, 15, 16, 23]
Output: [15, 16, 23]
Explanation: The middle node has value 15.
```

**Example 2:**
```
Input: head = [6, 2, 9, 4]
Output: [9, 4]
Explanation: Two middle nodes are 2 and 9; return the second one (9).
```

Constraints

  • The number of nodes in the list is in the range [1, 1000].
  • 1 ≤ Node.val ≤ 10^4

Hints

Try the problem first. If you get stuck, you can reveal hints one at a time.

Solution

Leaderboard

No entries yet for python.

Be the first — submit an accepted solution.