All problems

Mural Time-Lapse

Medium · design

A street artist paints a long wall made of cells cells in a row, numbered 0 to cells - 1. Every cell starts with colour 0 (bare wall). You are given a list of operations. operations[i] is one of "paint", "save", "wipe" or "look", and args[i] holds its arguments: [cell, colour] for a "paint", [] (empty) for a "save" or a "wipe", and [cell, photo] for a "look".

Return a list with the answer to every "save" and every "look", in the order they appear.

Examples

Example 1

Input: cells = 3, operations = ["paint", "save", "paint", "save", "look", "look", "look"], args = [[0, 5], [], [0, 8], [], [0, 0], [0, 1], [1, 1]]

Output: [0, 1, 5, 8, 0]

The two saves answer 0 and 1. Photo 0 shows cell 0 as 5, photo 1 shows it as 8, and cell 1 was never painted.

Example 2

Input: cells = 2, operations = ["paint", "paint", "save", "wipe", "save", "paint", "save", "look", "look", "look"], args = [[0, 4], [1, 6], [], [], [], [1, 9], [], [1, 0], [1, 1], [1, 2]]

Output: [0, 1, 2, 6, 0, 9]

The three saves answer 0, 1 and 2. Photo 0 shows cell 1 as 6. The wipe sets both cells back to 0, so photo 1 shows 0. Photo 2 is taken after cell 1 was painted 9.

Constraints