added Find All Groups of Farmland #351
Closed
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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 ?