m × n grid of cells. In one move it picks a color and fills any rectangle of cells with it solidly, covering whatever was in that rectangle before. There is one restriction: the robot may use each color at most once.
You are given a matrix wall, where wall[i][j] is the color the cell in row i and column j must have at the end. Return True if the robot can produce exactly this wall, and False otherwise.wall=[[3, 3, 3], [3, 5, 3], [3, 3, 3]] → True
First the whole wall is sprayed with color 3, then a 1×1 rectangle of color 5 goes into the centre.
wall=[[4, 4, 7], [4, 4, 7], [2, 2, 7]] → True
The order 4 → 2 → 7 works: a 2×2 square of color 4, a strip of color 2 along the bottom row and a column of color 7 on the right.
wall=[[1, 2], [2, 1]] → False
The rectangle around both cells of color 1 is the whole wall, so color 2 must be sprayed later. The same holds for color 2 with respect to color 1, which is a contradiction: this wall cannot be produced.
m == wall.length, n == wall[i].lengthwall[i][j] ≤ 60wall=[[3, 3, 3], [3, 5, 3], [3, 3, 3]]
True
Run checks the first 3 tests in your browser. Submit checks all 68 tests on the server, hidden ones included.