Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1992. Find All Groups of Farmland #19

Open
F4NT0 opened this issue Apr 20, 2024 · 1 comment
Open

1992. Find All Groups of Farmland #19

F4NT0 opened this issue Apr 20, 2024 · 1 comment
Assignees
Labels
Medium Medium Questions Ready to code Description from the Question was updated with code and text

Comments

@F4NT0
Copy link
Owner

F4NT0 commented Apr 20, 2024

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.

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.

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].

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.

Example 1:

image

  • Input: land = [[1,0,0],[0,1,1],[0,1,1]]
  • Output: [[0,0,0,0],[1,1,2,2]]
  • Explanation:
    - The first group has a top left corner at land[0][0] and a bottom right corner at land[0][0].
    - The second group has a top left corner at land[1][1] and a bottom right corner at land[2][2].

Example 2:

image

  • Input: land = [[1,1],[1,1]]
  • Output: [[0,0,1,1]]
  • Explanation:
    - The first group has a top left corner at land[0][0] and a bottom right corner at land[1][1].

Example 3:

image

  • Input: land = [[0]]
  • Output: []
  • Explanation:
    - There are no groups of farmland.

Constraints:

  • m == land.length
  • n == land[i].length
  • 1 <= m, n <= 300
  • land consists of only 0's and 1's.
  • Groups of farmland are rectangular in shape.
@F4NT0 F4NT0 added the Medium Medium Questions label Apr 20, 2024
@F4NT0 F4NT0 added this to the April Leetcode milestone Apr 20, 2024
@F4NT0 F4NT0 self-assigned this Apr 20, 2024
@F4NT0 F4NT0 added the Ready to code Description from the Question was updated with code and text label Apr 30, 2024
@F4NT0
Copy link
Owner Author

F4NT0 commented Apr 30, 2024

Topics: Array, Matrix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Medium Medium Questions Ready to code Description from the Question was updated with code and text
Projects
None yet
Development

No branches or pull requests

1 participant