O31

Remove N-th Node From End of List

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: ARRAY

Problem Statement & Objective

Given the head of a linked list, remove the n-th node from the end of the list and return its head.

Function Signature (Python)

remove_nth_node_from_end(nodes: list, head: int, k: int) -> list

Input & Output Contract

Output Rule:[yeni_bas, sonraki_listesi]. Baş silinince yeni_bas, eski başın eski sonraki indeksidir.

System Constraints

1 <= dugumler.length <= 1000
1 <= k <= düğüm sayısı
Döngü yoktur

Example Execution Walkthrough

[[1,1],[2,2],[3,3],[4,4],[5,-1]], bas = 0, k = 2
Sondan 2. düğüm indeks 3 (değer 4). 3. düğüm 5'e bağlanır.
yeni_bas = 0, sonraki = [1, 2, 4, -1, -1]

Aynı liste, k = 5: baş (indeks 0) silinir.
yeni_bas = 1, sonraki = [-1, 2, 3, 4, -1]

Example Test Scenarios (3)

Example 1: Sondan 2.
Input:[[[1,1],[2,2],[3,3],[4,4],[5,-1]],0,2]
Expected Output:[0,[1,2,4,-1,-1]]
Example 2: Tek Düğümü Sil
Input:[[[1,-1]],0,1]
Expected Output:[-1,[-1]]
Example 3: Başı Sil (k = n)
Input:[[[1,1],[2,2],[3,3],[4,4],[5,-1]],0,5]
Expected Output:[1,[-1,2,3,4,-1]]
Loading Python Editor...
Input Parameters
[
  [
    [
      1,
      1
    ],
    [
      2,
      2
    ],
    [
      3,
      3
    ],
    [
      4,
      4
    ],
    [
      5,
      -1
    ]
  ],
  0,
  2
]
Expected Output
[
  0,
  [
    1,
    2,
    4,
    -1,
    -1
  ]
]