|
| 1 | +1992\. Find All Groups of Farmland |
| 2 | + |
| 3 | +Medium |
| 4 | + |
| 5 | +You are given a **0-indexed** `m x n` binary matrix `land` where a `0` represents a hectare of forested land and a `1` represents a hectare of farmland. |
| 6 | + |
| 7 | +To keep the land organized, there are designated rectangular areas of hectares that consist **entirely** of farmland. These rectangular areas are called **groups**. No two groups are adjacent, meaning farmland in one group is **not** four-directionally adjacent to another farmland in a different group. |
| 8 | + |
| 9 | +`land` can be represented by a coordinate system where the top left corner of `land` is `(0, 0)` and the bottom right corner of `land` is `(m-1, n-1)`. Find the coordinates of the top left and bottom right corner of each **group** of farmland. A **group** of farmland with a top left corner at <code>(r<sub>1</sub>, c<sub>1</sub>)</code> and a bottom right corner at <code>(r<sub>2</sub>, c<sub>2</sub>)</code> is represented by the 4-length array <code>[r<sub>1</sub>, c<sub>1</sub>, r<sub>2</sub>, c<sub>2</sub>].</code> |
| 10 | + |
| 11 | +Return _a 2D array containing the 4-length arrays described above for each **group** of farmland in_ `land`_. If there are no groups of farmland, return an empty array. You may return the answer in **any order**_. |
| 12 | + |
| 13 | +**Example 1:** |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +**Input:** land = [[1,0,0],[0,1,1],[0,1,1]] |
| 18 | + |
| 19 | +**Output:** [[0,0,0,0],[1,1,2,2]] |
| 20 | + |
| 21 | +**Explanation:** |
| 22 | + |
| 23 | +The first group has a top left corner at land[0][0] and a bottom right corner at land[0][0]. |
| 24 | + |
| 25 | +The second group has a top left corner at land[1][1] and a bottom right corner at land[2][2]. |
| 26 | + |
| 27 | +**Example 2:** |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | +**Input:** land = [[1,1],[1,1]] |
| 32 | + |
| 33 | +**Output:** [[0,0,1,1]] |
| 34 | + |
| 35 | +**Explanation:** |
| 36 | + |
| 37 | +The first group has a top left corner at land[0][0] and a bottom right corner at land[1][1]. |
| 38 | + |
| 39 | +**Example 3:** |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | +**Input:** land = [[0]] |
| 44 | + |
| 45 | +**Output:** [] |
| 46 | + |
| 47 | +**Explanation:** There are no groups of farmland. |
| 48 | + |
| 49 | +**Constraints:** |
| 50 | + |
| 51 | +* `m == land.length` |
| 52 | +* `n == land[i].length` |
| 53 | +* `1 <= m, n <= 300` |
| 54 | +* `land` consists of only `0`'s and `1`'s. |
| 55 | +* Groups of farmland are **rectangular** in shape. |
0 commit comments