Tagged Command Undo
MediumStacks · Netflix
An internal admin console keeps a log of commands, and each command carries a tag (for example the service it touched). Process operations in order. Each operation is one of:
["run", command_id, tag]: append a new command to the log. It starts active.["undo"]: deactivate the most recently run command that is still active. If no command is active, do nothing.["undo_tag", tag]: deactivate the most recently run command that is still active and has exactly this tag. If there is none, do nothing.
An undone command stays undone; it is never re-activated, and later undos skip over it.
Return the ids of the commands that are still active at the end, in the order they were run.
Example 1
- Input:
- operations = [["run", "deploy-api", "api"], ["run", "flush-cache", "cache"], ["run", "scale-api", "api"], ["undo_tag", "api"], ["undo"], ["run", "restart-db", "db"]]
- Output:
- ["deploy-api", "restart-db"]
- Explanation
undo_tag apiremoves the latest activeapicommand,scale-api. The plainundothen removes the latest active command overall, which is nowflush-cache.restart-dbruns afterwards, sodeploy-apiandrestart-dbremain.
Example 2
- Input:
- operations = [["run", "a", "x"], ["run", "b", "y"], ["undo_tag", "y"], ["undo"]]
- Output:
- []
- Explanation
bis undone by tag. The globalundoskipsb, because it is no longer active, and undoesa.
Example 3
- Input:
- operations = [["run", "a", "X"], ["undo_tag", "x"], ["undo_tag", "z"]]
- Output:
- ["a"]
- Explanation
- Tags are case-sensitive, so neither
xnorzmatchesa's tagX. Both undos do nothing.
Constraints
- 0 ≤ operations.length ≤ 105
- Command ids are distinct strings; tags are strings and are compared exactly (case-sensitive).