FastPrepRemove Nth Node From End

Remove Nth Node From End

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

Remove the n-th node from the end of the singly linked list and return its head.

Function

removeNthFromEnd(head: ListNode, n: int) → ListNode

Examples

Example 1

head = [1,2,3,4,5]n = 2return = [1,2,3,5]

The value 4 is second from the end.

Constraints

  • The list contains between 1 and 10^5 nodes.
  • 1 <= n <= list length.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public ListNode removeNthFromEnd(ListNode head, int n) {
  // Write your code here.
}
head[1,2,3,4,5]
n2
expected[1,2,3,5]
Checking account…