Flower Placement
Asked at Google
Reported by the problem's creator, not verified
A garden is a square grid given as grid, a list of n strings of n characters each. Each character is 'H' for a house or '0' for an empty cell. Two cells are neighbours when they share an edge. You may plant a flower in any empty cell.
Examples
Example 1
Input: grid =
["H00","000","00H"]Output:
trueExplanation: Put one flower at row 0, column 1 (next to the top-left house) and one at row 1, column 2 (next to the bottom-right house). They share no row or column, so a valid placement exists.
Example 2
Input: grid =
["HH","00"]Output:
falseExplanation: The top-left house can use only the cell below it and the top-right house can use only the cell below it, and those two cells are in the same row. A row holds at most one flower, so there is no valid placement.