Remove Nth From End

Python data engineering interview problem. Difficulty: intermediate. Pattern: Linked Lists. About 14 minutes. Part of the Pro drill bank.

Remove the nth node from the end of a value-list. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

A failed request often needs the item n positions from the end removed. Counting from the front is awkward when the list is streamed. Remove the nth node from the end and return the remaining values. The first node from the end is n = 1, and the output keeps all other values in order. Write remove_nth_from_end(values: list, n: int) -> list. Removing the second from the end in [1, 2, 3, 4, 5] removes 4 and gives [1, 2, 3, 5]. The starter file already has the function name and harness print lines. Keep them and fill only the function body.

Requirements

  • Remove exactly the requested position from the end.
  • Keep the order of the other values.
  • Return the resulting list.

Constraints

  • n is a valid positive position for the given list.
  • A two-pointer gap or a dummy head handles removal of the first node.

Examples

Input: remove_nth_from_end([1, 2, 3, 4, 5], 2) Output: [1, 2, 3, 5] Remove 4 (2nd from end).

Topics: lakebench, python, two pointers, list api.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Remove Nth From End

Interview-style drill: Remove the nth node from the end of a value-list.

Implement `remove_nth_from_end(values: list, n: int) -> list`. Example: `[1, 2, 3, 4, 5], 2` → `[1, 2, 3, 5]`. Keep the harness.