Flower Placement

Asked at GoogleOnsite

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

  1. Example 1

    Input: grid = ["H00","000","00H"]

    Output: true

    Explanation: 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.

  2. Example 2

    Input: grid = ["HH","00"]

    Output: false

    Explanation: 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.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.