Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Remove the nth node from the end

Hardware interview practice

Remove the nth node from the end

MediumLinked ListsSystemVerilog

Remove the nth node from the end of a singly linked list in one traversal and return the head.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
head = 1 -> 2 -> 3 -> 4 -> 5, n = 2
Expected output
1 -> 2 -> 3 -> 5

Keeping the lead pointer two nodes ahead places the trailing pointer immediately before node 4.

What to cover

Requirements

  1. Treat n as one-based from the tail.
  2. Leave the list unchanged when n is not positive or exceeds the list length.
  3. Correctly remove the head when n equals the list length.
Continue practicing

Related questions

Linked ListsReverse a singly linked list→Linked ListsDetect a linked-list cycle→Linked ListsFind the middle node→
asic.fyi · Learn silicon end to end.info@asic.fyi