The Find All Groups of Farmland interview question provides a 2D binary grid where 1s represent farmland and 0s represent forested land. Farmland is organized into rectangular groups. You are guaranteed that these rectangles are disjoint (they don't touch even diagonally). Your task is to find the coordinates of the top-left and bottom-right corners of every farmland rectangle.
Meta and Google use this problem to evaluate a candidate's ability to navigate 2D matrices and identify connected components. It’s a variation of the "Number of Islands" problem but with stricter geometric constraints (rectangles). It evaluation your proficiency with Graph Traversal interview patterns and your ability to extract bounding box information from a set of connected points.
There are two main ways to solve this:
Grid:
[1, 1, 0]
[1, 1, 0]
[0, 0, 1]
[0...1, 0...1] as visited.[[0,0,1,1], [2,2,2,2]].Always look at the problem constraints. The "guaranteed rectangular" and "disjoint" conditions are massive hints that simplify the connectivity logic. You don't need a full BFS/DFS if you can just follow the edges of the rectangle.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minesweeper | Medium | Solve | |
| Coloring A Border | Medium | Solve | |
| Pacific Atlantic Water Flow | Medium | Solve | |
| The Maze | Medium | Solve | |
| Shortest Bridge | Medium | Solve |