Loading
Loading
A stage must be removed from a processing chain, identified by its distance from the end rather than from the start.
Remove the n-th stage counting from the end and return the head of the resulting chain.
1 → 2 → 3 → 4 → 5, n = 2advance lead 2 stepslead at 3move both to the endtrail lands just before 4unlinktrail.next = trail.next.next1 → 2 → 3 → 5Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
Example 2
Removing the only node leaves an empty chain.
Example 3