Ctrl K

One Repaint to a Solid Block

Easy
A floor is laid out as a 3×3 grid of tiles: tiles[i][j] is 'B' for a black tile or 'W' for a white one. You may repaint **at most one** tile. Return True if the floor can then contain a 2×2 block of tiles that are all the same colour, and False otherwise.
Example 1
tiles=[['W', 'B', 'W'], ['B', 'B', 'W'], ['W', 'W', 'B']] → True

Repainting the top-left tile to B makes the top-left 2×2 block entirely black.

Example 2
tiles=[['W', 'B', 'W'], ['B', 'W', 'B'], ['W', 'B', 'W']] → False

Every 2×2 block has two tiles of each colour, so one repaint is never enough.

Example 3
tiles=[['B', 'W', 'W'], ['B', 'W', 'W'], ['B', 'B', 'B']] → True

The top-right block is already all white, so no repaint is needed.

Constraints
  • len(tiles) == 3
  • len(tiles[i]) == 3
  • tiles[i][j] is 'B' or 'W'
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFlanking Move on the Board MediumA Word in a Crossword Slot MediumColumns That Cover Rows MediumPrimes Along Grid Rays MediumThree Rectangles Over the Ones Hard
loading Python…
Input
tiles=[['W', 'B', 'W'], ['B', 'B', 'W'], ['W', 'W', 'B']]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 13 tests on the server, hidden ones included.