DescriptionQ236
Q236FWASIC interview problem
Remove the nth node from the end
TechniquesLinked listTwo pointers
DifficultyMedium
TopicLinked Lists
LanguageSystemVerilog
Requirements3 checkpoints
01
Problem
Remove the nth node from the end of a singly linked list in one traversal and return the head.
Example input and output
Use this case to check your interpretationInput
head = 1 -> 2 -> 3 -> 4 -> 5, n = 2Output
1 -> 2 -> 3 -> 5Explanation
Keeping the lead pointer two nodes ahead places the trailing pointer immediately before node 4.
02
Requirements (3)
- Treat n as one-based from the tail.
- Leave the list unchanged when n is not positive or exceeds the list length.
- Correctly remove the head when n equals the list length.
