Find All Groups of Farmland | DFS | BFS | Brute Force | Leetcode 1992 | codestorywithMIK

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=3ZaQTCH83fY



Duration: 32:38
4,048 views
181


Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 92nd Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve another very good 2D Array problem : Find All Groups of Farmland | DFS | BFS | Brute Force | Same as Island Perimeter | Leetcode 1992 | codestorywithMIK

I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY.
We will do live coding after explanation and see if we are able to pass all the test cases.
Also, please note that my Github solution link below contains both C++ as well as JAVA code.

Problem Name : Find All Groups of Farmland | DFS | BFS | Brute Force | Same as Island Perimeter | Leetcode 1992 | codestorywithMIK
Company Tags : Amazon, Microsoft
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Arrays/Find%20All%20Groups%20of%20Farmland.cpp
Leetcode Link : https://leetcode.com/problems/find-all-groups-of-farmland/


My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls
My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w
My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK

Approach Summary :
**Approach-1 (DFS):**

This approach utilizes Depth-First Search (DFS) to traverse the land matrix. It starts from each unvisited land cell marked as 1 and explores all connected land cells, marking them as visited (0). During the traversal, it records the coordinates of the top-left and bottom-right corners of each connected land area. The time complexity of this approach is O(m*n), where m and n are the dimensions of the land matrix. The space complexity is O(1) auxiliary space and O(m*n) due to system stack space because of recursion.

**Approach-2 (BFS):**

Here, Breadth-First Search (BFS) is employed to traverse the land matrix. Similar to DFS, it starts from unvisited land cells and explores all connected land cells iteratively. It also records the coordinates of the top-left and bottom-right corners of each connected land area. The time complexity remains O(m*n), while the space complexity is O(m*n) due to the usage of a queue for BFS.

**Approach-3 (Brute Force Greedy):**

This approach utilizes a brute-force greedy strategy. It iterates through each cell of the land matrix, identifying the start of each unvisited land area. It then extends the area to the right and downwards, marking all contiguous land cells as visited (0) and recording the coordinates of the top-left and bottom-right corners. The time complexity is O(m*n), and the space complexity is O(1) since it doesn't require additional space proportional to the input size.

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

✨ Timelines✨
00:00 - Introduction

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024




Other Videos By codestorywithMIK


2024-04-29Number of Wonderful Substrings | Clear Intuition | Full Dry Run | Leetcode 1915 | codestorywithMIK
2024-04-29Minimum Number of Operations to Make Array XOR Equal to K | Easy | Leetcode 2997 | codestorywithMIK
2024-04-27Travel Mood 🌍 #codestorywithmik
2024-04-27Freedom Trail | Recursion | Memoization | Bottom Up | Detailed | Leetcode 514 | codestorywithMIK
2024-04-26Minimum Falling Path Sum II | 4 Approaches | Detailed Dry Run | Leetcode 1289 | codestorywithMIK
2024-04-24Longest Ideal Subsequence | LIS Variant | Bottom Up | Optimal | Leetcode 2370 | codestorywithMIK
2024-04-23N-th Tribonacci Number | 3 Approaches | AMAZON | Leetcode 1137 | codestorywithMIK
2024-04-22Minimum Height Trees | Know Every Detail | Why BFS | GOOGLE | Leetcode 310 | codestorywithMIK
2024-04-21Open the Lock | Why BFS | Similar Pattern Problems | META | Leetcode 752 | codestorywithMIK
2024-04-21Find Edges in Shortest Paths | Dijkstra's Algo | Full Intuition | Leetcode 3123 | codestorywithMIK
2024-04-20Find All Groups of Farmland | DFS | BFS | Brute Force | Leetcode 1992 | codestorywithMIK
2024-04-18Number of Islands | DFS | BFS | Same as Island Perimeter | Leetcode 200 | codestorywithMIK
2024-04-17Island Perimeter | 3 Approaches | Google | Leetcode 463 | codestorywithMIK
2024-04-16Smallest String Starting From Leaf | DFS | BFS | Google | Leetcode 988 | codestorywithMIK
2024-04-14Edit Distance | Recursion | Memo | Bottom Up | DP On Strings | Leetcode 72 | DP Concepts & Qns-21
2024-04-13Sum of Left Leaves | 2 Approaches | META | Leetcode 404 | codestorywithMIK
2024-04-12Maximal Rectangle | Multiple Hidden Problems | Intuition | Leetcode 85 | codestorywithMIK
2024-04-12One Love = CODING ❤️👨🏻‍💻
2024-04-10Remove K Digits | Intuition | Dry Run | Leetcode 402 | codestorywithMIK
2024-04-09Reveal Cards In Increasing Order | 2 Approaches | Leetcode 950 | codestorywithMIK
2024-04-09Time Needed to Buy Tickets | 3 Approaches | Leetcode 2073 | codestorywithMIK