Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Remove Nth Node From End of List

Medium

Topics
Linked ListTwo Pointers

Given the head of a linked list, remove the k-th node from the end and return the head. (LeetCode calls this parameter n.)

Example 1

Input:  head = [1,2,3,4,5], k = 2
Output: [1,2,3,5]

Example 2

Input:  head = [1], k = 1
Output: []

Constraints

  • 1 <= number of nodes <= 30
  • 1 <= k <= number of nodes
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access