Skip to content

Commit 37741b5

Browse files
committed
1992. Find All Groups of Farmland: RETRY
1 parent ffade38 commit 37741b5

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

src/solution/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1500,3 +1500,4 @@ mod s1985_find_the_kth_largest_integer_in_the_array;
15001500
mod s1986_minimum_number_of_work_sessions_to_finish_the_tasks;
15011501
mod s1987_number_of_unique_good_subsequences;
15021502
mod s1991_find_the_middle_index_in_array;
1503+
mod s1992_find_all_groups_of_farmland;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* [1992] Find All Groups of Farmland
3+
*
4+
* 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.
5+
* 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.
6+
* 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 (r1, c1) and a bottom right corner at (r2, c2) is represented by the 4-length array [r1, c1, r2, c2].
7+
* 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.
8+
*
9+
* Example 1:
10+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/07/27/screenshot-2021-07-27-at-12-23-15-copy-of-diagram-drawio-diagrams-net.png" style="width: 300px; height: 300px;" />
11+
* Input: land = [[1,0,0],[0,1,1],[0,1,1]]
12+
* Output: [[0,0,0,0],[1,1,2,2]]
13+
* Explanation:
14+
* The first group has a top left corner at land[0][0] and a bottom right corner at land[0][0].
15+
* The second group has a top left corner at land[1][1] and a bottom right corner at land[2][2].
16+
*
17+
* Example 2:
18+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/07/27/screenshot-2021-07-27-at-12-30-26-copy-of-diagram-drawio-diagrams-net.png" style="width: 200px; height: 200px;" />
19+
* Input: land = [[1,1],[1,1]]
20+
* Output: [[0,0,1,1]]
21+
* Explanation:
22+
* The first group has a top left corner at land[0][0] and a bottom right corner at land[1][1].
23+
*
24+
* Example 3:
25+
* <img alt="" src="https://assets.leetcode.com/uploads/2021/07/27/screenshot-2021-07-27-at-12-32-24-copy-of-diagram-drawio-diagrams-net.png" style="width: 100px; height: 100px;" />
26+
* Input: land = [[0]]
27+
* Output: []
28+
* Explanation:
29+
* There are no groups of farmland.
30+
*
31+
*
32+
* Constraints:
33+
*
34+
* m == land.length
35+
* n == land[i].length
36+
* 1 <= m, n <= 300
37+
* land consists of only 0's and 1's.
38+
* Groups of farmland are rectangular in shape.
39+
*
40+
*/
41+
pub struct Solution {}
42+
43+
// problem: https://leetcode.com/problems/find-all-groups-of-farmland/
44+
// discuss: https://leetcode.com/problems/find-all-groups-of-farmland/discuss/?currentPage=1&orderBy=most_votes&query=
45+
46+
// submission codes start here
47+
48+
impl Solution {
49+
pub fn find_farmland(land: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
50+
vec![]
51+
}
52+
}
53+
54+
// submission codes end
55+
56+
#[cfg(test)]
57+
mod tests {
58+
use super::*;
59+
60+
#[test]
61+
#[ignore]
62+
fn test_1992_example_1() {
63+
let land = vec![vec![1, 0, 0], vec![0, 1, 1], vec![0, 1, 1]];
64+
65+
let result = vec![vec![0, 0, 0, 0], vec![1, 1, 2, 2]];
66+
67+
assert_eq!(Solution::find_farmland(land), result);
68+
}
69+
70+
#[test]
71+
#[ignore]
72+
fn test_1992_example_2() {
73+
let land = vec![vec![1, 1], vec![1, 1]];
74+
75+
let result = vec![vec![0, 0, 1, 1]];
76+
77+
assert_eq!(Solution::find_farmland(land), result);
78+
}
79+
80+
#[test]
81+
#[ignore]
82+
fn test_1992_example_3() {
83+
let land = vec![vec![0]];
84+
85+
let result: Vec<Vec<i32>> = vec![];
86+
87+
assert_eq!(Solution::find_farmland(land), result);
88+
}
89+
}

0 commit comments

Comments
 (0)