leetle

Daily challenge for 2026-09-01

609. Limited Capacity Undo Stack

You are simulating a text editor with a limited undo history. You are given a list of strings actions and an integer capacity.

Each action is either a single lowercase letter representing a typed character, or the string "UNDO" which reverts the most recently typed character currently in the buffer.

The buffer has a maximum capacity. If typing a character causes the buffer size to exceed capacity, the oldest character (at the bottom of the stack) is permanently discarded and can no longer be restored or affected by UNDO.

Return the final state of the buffer as a single string.

Example:
Input: actions = ["a", "b", "c", "UNDO"], capacity = 2
Output: "b"

Run this challenge interactively in Python or JavaScript when the app loads.