Zero To DSAZero To DSA
Privacy Policy
Linked List CyclePalindrome Linked List

Remove Nth Node From End

medium
Time: O(n)
Space: O(1)

Given the head of a linked list, remove the nth node from the end of the list and return its head.

Constraints

  • 1 <= n <= number of nodes

Examples

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