Tap here to switch tabs
Problem
Submissions

Problem: Find All Groups of Farmland

med
30 min
Try to solve the Find All Groups of Farmland problem.

Statement

You are given a 00 indexed m×nm \times n binary matrix land where a value of 00 represents a non farmland cell and a value of 11 represents a farmland cell.

Farmland cells are organized into rectangular groups. A group of farmland is defined as a maximal rectangle of adjacent 11 values such that no two groups share a border.

Every group of farmland can be uniquely represented by a 44 element list [r1,c1,r2,c2][r_1, c_1, r_2, c_2], where (r1,c1)(r_1, c_1) represents the top left coordinate and (r2,c2)(r_2, c_2) represents the bottom right coordinate of the rectangle.

Return a 22D array containing the coordinates [r1,c1,r2,c2][r_1, c_1, r_2, c_2] for every group of farmland in land. The groups may be returned in any order.

Constraints:

  • m ==== land.length

  • n ==== land[i].length

  • 1≤1 \leq m, n ≤300\leq 300

  • land consists of only 00’s and 11’s.

  • Groups of farmland are rectangular in shape.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Find All Groups of Farmland

med
30 min
Try to solve the Find All Groups of Farmland problem.

Statement

You are given a 00 indexed m×nm \times n binary matrix land where a value of 00 represents a non farmland cell and a value of 11 represents a farmland cell.

Farmland cells are organized into rectangular groups. A group of farmland is defined as a maximal rectangle of adjacent 11 values such that no two groups share a border.

Every group of farmland can be uniquely represented by a 44 element list [r1,c1,r2,c2][r_1, c_1, r_2, c_2], where (r1,c1)(r_1, c_1) represents the top left coordinate and (r2,c2)(r_2, c_2) represents the bottom right coordinate of the rectangle.

Return a 22D array containing the coordinates [r1,c1,r2,c2][r_1, c_1, r_2, c_2] for every group of farmland in land. The groups may be returned in any order.

Constraints:

  • m ==== land.length

  • n ==== land[i].length

  • 1≤1 \leq m, n ≤300\leq 300

  • land consists of only 00’s and 11’s.

  • Groups of farmland are rectangular in shape.