Problem 115201 · easy · Phase 01 Prerequisites & Setup

Undo the Last Actions

lists · pop · loops

An editor keeps a history of actions as a list, oldest first. Write undo(history, k) that returns a new list with the last k actions removed. If k is larger than the number of actions, return an empty list. The original list must stay unchanged.

Examples

Input:  history = ["open", "type", "save", "close"], k = 2
Output: ["open", "type"]

Input:  history = ["open"], k = 3
Output: []

Constraints

  • 0 <= len(history) <= 5000
  • 0 <= k <= 10000

Goals

  • Remove items from the end of a list with pop
  • Stop safely when the list runs out
Starting Python…