algorythms
Fast & Slow Pointers
LC #876Easy

Middle of the Linked List

Fast & Slow Pointers
AmazonGoogleMicrosoft

Problem

Find the middle node of a linked list in one pass.

linked-listfast-slow-pointers

Constraints

  • 1 ≤ n ≤ 100
  • 1 ≤ Node.val ≤ 100

Example

Inputhead = [1, 2, 3, 4, 5]
Output[3, 4, 5]
Why

Middle node is 3 (index 2). For [1,2,3,4,5,6], return node 4 (second middle)

Hints — reveal one at a time