MediumLinked ListsAI interview only
Remove Nth Node From End of List
Asked atmetaamazongoogleapplemicrosoftbloomberg
01 · Problem
Given the head of a linked list, remove the nth node from the end of the list and return its head.
02 · Examples
Example 01
Input
head = [1,2,3,4,5], n = 2
Output
[1,2,3,5]
The 2nd node from the end is 4. After removing it, the linked list becomes 1 -> 2 -> 3 -> 5.
Example 02
Input
head = [1], n = 1
Output
[]
There is only one node in the list and it is removed, resulting in an empty list.
Example 03
Input
head = [1,2], n = 1
Output
[1]
The 1st node from the end is 2. After removing it, the linked list becomes just [1].
03 · Constraints
- 01The number of nodes in the list is sz.
- 021 <= sz <= 30
- 030 <= Node.val <= 100
- 041 <= n <= sz
04 · Optimal complexity
- Time
- O(n)
- Space
- O(1)
05 · Two ways to work on it
Practice it alone or rehearse it as an interview.
Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.