FastPrepMatrix Flower-House Planting Plans
Problems/Matrix Flower-House Planting Plans

Matrix Flower-House Planting Plans

Google logoGoogle● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives the grid symbols, the row and column exclusion, one exclusive adjacent flower per house, a yes-or-no base result, and a follow-up to list all plans. A last commenter asks whether exclusivity is part of the structure or part of the assignment, and the author does not reply. Here we use the structure reading, and every final flower must serve exactly one house. Our version is about 85% the same as the reported question.

You are given a rectangular grid containing H (house), F (an existing flower), and O (an empty plot). You may change selected O cells to F; houses and existing flowers cannot be changed.

A final grid is valid when:

  • Every row and every column contains at most one flower.
  • Every house has exactly one orthogonally adjacent flower.
  • Every flower is orthogonally adjacent to exactly one house, so no flower is shared by two houses and no irrelevant flower is planted.

Return every valid final grid. Encode one grid by joining its rows with /, and return the encodings in lexicographic order. Return an empty array when no valid planting exists.

The base interview question asks only whether a valid planting exists. The returned list implements the follow-up that asks for every possible planting; the base answer is true exactly when the returned list is nonempty.

Function

flowerHousePlans(grid: String[]) → String[]

Examples

Example 1

grid = ["HOO","OOH"]return = ["HOF/FOH"]
grid
0120HOO1OOH
→
return
01234560HOF/FOH

The top-left house uses the flower at row 1, column 0, and the bottom-right house uses the flower at row 0, column 2. The flowers occupy different rows and columns.

Example 2

grid = ["HOO","OOO","OOH"]return = ["HFO/OOF/OOH","HOO/FOO/OFH"]
grid
0120HOO1OOO2OOH
→
return
0123456789100HFO/OOF/OOH1HOO/FOO/OFH

There are two valid ways to give each house one exclusive neighboring flower while keeping flower rows and columns unique.

Example 3

grid = ["HFH"]return = []
grid
0120HFH

The existing flower touches both houses, so it cannot belong exclusively to either one.

Constraints

  • 1 <= grid.length <= 6.
  • 1 <= grid[r].length <= 6, and all rows have equal length.
  • Every cell is H, F, or O.
  • There are at most 10 houses.
  • The number of valid returned grids is at most 10000.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Cats, Rabbits, and Snails Board GameAsana · ONSITE INTERVIEW
  • Boggle Word FinderBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Enumerate Character Paths to a MarkerTesla · ONSITE INTERVIEWTesla interview questions
  • Eight-Direction Word SearchMotive · ONSITE INTERVIEWMotive interview questions
  • Trace a Word Through a Letter GridExpedia · ONSITE INTERVIEWExpedia interview questions
  • Word Search with Eight-Direction AdjacencyMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Find a Word in a Letter GridAdobe · PHONE SCREENAdobe interview questions
  • Optimal Account BalancingAmazon · ONSITE INTERVIEW
  • Sudoku Puzzle SolverConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
  • Optimal Account BalancingPinterest · PHONE SCREEN · ONSITE INTERVIEWPinterest interview questions

Interview reports that mention this question

  • Google Early Career R1 and Bay Area Onsite: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[] flowerHousePlans(String[] grid) {
        // write your code here
    }
}
Checking account…