The moment I saw 'one per row, one per column' I just thought N-Queens and went straight to DFS with backtracking.
Model the problem as a constraint satisfaction problem where each row and column must have exactly one flower, and each house must be adjacent to at least one flower. Use backtracking with pruning to assign flowers row by row, ensuring column constraints and house coverage are satisfied. Optimize by checking feasibility early and using heuristics like placing flowers near uncovered houses.
Pro tip: Clarify that the solution is not unique and that returning any valid arrangement is acceptable; this shows you understand the problem's flexibility and can focus on correctness over optimality. Also, mention that you would test edge cases like grids with no houses or houses in corners.
Restate the problem: place exactly one flower per row and column, and ensure every house has at least one adjacent flower. Identify that adjacency includes up, down, left, right (not diagonal).
Select backtracking as the primary method because it naturally handles the row-by-row placement and column uniqueness constraint. Consider alternative formulations like exact cover or SAT, but backtracking is simpler to implement.
For each row, try placing a flower in each column not yet used. After placement, check if any house in the current or previous rows becomes impossible to cover (e.g., a house with no adjacent empty cells left for future flowers). Prune if constraints are violated.
Write code to recursively assign flowers, backtrack when stuck, and return the first valid arrangement. Test with small grids and edge cases (e.g., all houses, no houses, houses in corners) to verify correctness.
Explain that worst-case time is O(N!) due to permutations, but pruning reduces practical runtime. Mention potential optimizations like ordering rows by number of houses or using bitmasks for column usage.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.