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

73. Remove Nth Node From End of List

MediumDay 22 of 60Linked List

Given the head of a linked list and an integer n, remove the n-th node counted from the end of the list and return the head of the updated list. Try to do it in a single pass.

Example 1
Input: head = [1,2,3,4,5], n = 2
Output: [1,2,3,5]
The 2nd node from the end is 4.
Example 2
Input: head = [1], n = 1
Output: []
Example 3
Input: head = [1,2], n = 1
Output: [1]
Constraints
  • The list has `sz` nodes, 1 <= sz <= 30
  • 0 <= Node.val <= 100
  • 1 <= n <= sz
Hints
Frequently asked at: Meta, Amazon, Microsoft, Adobe
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