Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

72. Middle of the Linked List

EasyDay 22 of 60Linked List

Given the head of a singly linked list, return its middle node. If the list has an even number of nodes there are two middle nodes; return the second one. The judge prints the list starting from the node you return.

Example 1
Input: head = [1,2,3,4,5]
Output: [3,4,5]
The middle node is 3.
Example 2
Input: head = [1,2,3,4,5,6]
Output: [4,5,6]
The middles are 3 and 4; return the second one.
Constraints
  • The list has 1 to 100 nodes
  • 1 <= Node.val <= 100
Hints
Frequently asked at: Amazon, Apple, Adobe, Zoho
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min