Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Remove Nth Node From End of List

Medium
linked-listtwo-pointers

Remove the k-th node from the end of a linked list and return the head. Try to do it in one pass.

Input

  • Line 1: the list values
  • Line 2: integer k (1 ≤ k ≤ length)

Output: the resulting list's values, space-separated.

Example 1
Input:
1 2 3 4 5
2
Output:
1 2 3 5
Example 2
Input:
1
1
Output:
Example 3
Input:
1 2
1
Output:
1

Constraints

  • 1 ≤ list length ≤ 30
  • 1 ≤ k ≤ length
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.