Skip to content

Conversation

@shreyasri258
Copy link

@shreyasri258 shreyasri258 commented Nov 15, 2022

Pull Request Template

Description

Difficulty level:Medium
Tags:DFS,BFS,Array,Matrix

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

Solution Approach:
The key idea here to start a normal dfs with each of the most top-left corner of grid and visit all the adjacent nbrs which have value 1 means farmland.
Now we keep taking the maximum value of x and y from grid where we can reach.
Because we have rectanglular shapes maximum x and maximum y we can visit will be our most right-bottam cell which we can visit for the current iteration.

Put check marks:

Have you made changes in README file ?

  • [ ✓] Added problem & solution under correct topic.
  • Specified Space & Time complexity.
  • [✓ ] Specified difficulty level, tag & Note(if any).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant