---
title: "1992. Find All Groups of Farmland"
url: "https://laigary.com/interview/coding/1992-find-all-groups-of-farmland"
type: "note"
section: "coding"
date: "2025-05-04"
updated: "2025-05-04"
tags: ["Graph", "Breadth-First Search", "Depth-First Search"]
---

# 1992. Find All Groups of Farmland

[1992\. Find All Groups of Farmland](https://leetcode.com/problems/find-all-groups-of-farmland/)

```python
class Solution:
    def findFarmland(self, land: List[List[int]]) -> List[List[int]]:
        res = []

        m = len(land)
        n = len(land[0])

        def helper(i, j):
            k = i
            w = j
            while k < m and land[k][j] == 1:
                k += 1
            while w < n and land[i][w] == 1:
                w += 1
            for x in range(i, k):
                for y in range(j, w):
                    land[x][y] = 0
            
            return [i, j, k - 1, w - 1]

        res = []
        for i in range(m):
            for j in range(n):
                if land[i][j] == 1:
                    res.append(helper(i, j))
        
        return res


```
