Glad to know that you liked the content and thank you for appreciating. If you people will constantly keep on supporting and loving us, then soon we will reach heights.
Sir , literally , u're amazing,Your explanation is quite simple and even a 5th standard student can grasp it...Keep teaching and helping students....Thanx a lot..👍👍
sir, I saw a leetcode solution where someone did it without using the visited boolean matrix. you simply change the grid from 0 to 1 after you are done checking and traversing it in the main for loop(that calls for every cell), so it becomes useless and doesn't get repeated again. better space and time optimization!
@@pranavverma5291 jo main for loop se call aayegi vo to 0 ke liye aayegi aage recursion calls jo hai vo base case me hi check kar rahi hai ke arr[ i ][ j ] = 1 to return; yaani us point ke aage sirf 0 wale jaa payenge
Glad to hear that for better experience and well organised content. visit - nados.pepcoding.com Don't forget to follow us on Instagram instagram.com/pepcoding/
Thanks a lot sumit bhai, bahot hi badhiya explanation. But ek baat samajh nai aa rhi ki itna mast lecture hone ke baad bhi views count kam kyo hai, soo sad Aapne itna sahi explain kiya ki I am able to reduce the space complexity further, here is the code The idea is once we found the island then to track whether this node is visited or not, we can mark current element as 0 public int numIslands(char[][] a) { int count = 0; int row = a.length; int column = a[0].length; for(int i = 0; i
Guru Ji yeh toh pure recursion ka question ho gaya. Recursion which is complex. GRAPH wali feeling nahi aayi isme. But learnt a lot again about recursion
Your content is amazing. It's helping me so much in interview preparation. Can you also include an explanation of time & space complexity in your future videos?
Glad to know that you liked the content and thank you for appreciating. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem. Keep learning and keep loving Pepcoding😊
I have a doubt, suppose in above example used, in the rightmost island there is land i.e 0 in last row, left of last column.. So according to explanation that if the pointer goes to last column, it should return, then it won't check on left side of the rightmost-bottom 0, making a new island on left side, am I thinking right?
@@jobanpreetsingh2370 lot of sources you can find on web but most importantly when you solve the problem always try to understand it's logic,then easily you can able to find complexity. Just practice more and more.
This question can also be done using DSU Data structure. Code-> class DSU { public: vector parent; vector rank; DSU(int v) { for(int i=0;irank[lv]) parent[lv]=lu; else if(rank[lu]
Instead of having separate Boolean array for visited can't we have same input array and mark visited as 2. Then our space complexity would be O(1) , Correct me if I'm wrong...
we can do that, but ideally we shouldn't modify the original matrix as it's not a good practice. If your interviewer allows, then you can use this approach.
Thankyou beta! I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Thanks for liking and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Is tarah ka graph flood fill mei b diya gya tha na aur uss question mei basically humne dfs samjha tha is tarah k graph lete hue..aur is question mei hum log number of connected component nikal rha h same tarah k graph ko lete hue.. am I rit sir??
Sir isme mujhe what and how samja par why? nai samja. And me ye video series me dekthe hue aaya tha... meko ye nai samja ki hume ye problem ko iss way me he kyu apporach kiya.
beta asal mei ye samjhna hai ki wo 2d matrix ke cell vertices hain aur edges unke beech hai. ye ek poori variety hai jisme graph aise 2d array ki form mei dia jata hai aur cells vertex ban jate hain. ek baar ye realise kar lia to question to sirf get connected component he tha. agar aapko gcc ata hota aur ye dekhna ata hota to it was obvious. ab is tarah ke next questions mei aapke paas ye skill hogi.
So nice of you and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Sir your videos are addictive! Thank you so much for your efforts, you've done a great help to many coding aspirants like me
Great work sir .I'm shocked u have few likes.u deserve much more than this never stop teaching u r a best teacher . Every word make sense, thank u sir
Glad to know that you liked the content and thank you for appreciating. If you people will constantly keep on supporting and loving us, then soon we will reach heights.
Sir , literally , u're amazing,Your explanation is quite simple and even a 5th standard student can grasp it...Keep teaching and helping students....Thanx a lot..👍👍
great way of teaching, i never solved any graph question earlier but after seeing your's videos ,i feel like graph is so easy.😀
very very underrated channel, one of the best explanation I've found till now for java
After watching recursion playlist of yours this feels easier as compared to others 😀😀
crystal clear explanation sir ! no need to re-do the video
Thumbs up!
why we dont need to write visited[i][j]=0 (backtracking) after making all the 4 calls ?
awesome series for a beginner to start graph topic and get to know in-depth knowledge of problem solving techninque for graph ques
Glad it was helpful! pdhtee rhiee or share krtee rhiee
i left this question in one of my coding rounds considering it to be a very difficult question .... sumeet sir you make everything so easy for us : )
Which company mam ?
@@jobanpreetsingh2370 citibank
sir, I saw a leetcode solution where someone did it without using the visited boolean matrix. you simply change the grid from 0 to 1 after you are done checking and traversing it in the main for loop(that calls for every cell), so it becomes useless and doesn't get repeated again. better space and time optimization!
yes, it is completely fine
best!! there's some magic in your explanation!! thankyou sir❤️
I always like the video before it starts...I am aware that by default it is going to clear the concept of the question...
why we dont need to write visited[i][j]=0 after making all the 4 calls ?
@@pranavverma5291 jo main for loop se call aayegi vo to 0 ke liye aayegi
aage recursion calls jo hai vo base case me hi check kar rahi hai ke arr[ i ][ j ] = 1 to return;
yaani us point ke aage sirf 0 wale jaa payenge
thank u so much sir,after wasting 2 hours now i understand the concept
Glad to hear that for better experience and well organised content.
visit - nados.pepcoding.com
Don't forget to follow us on Instagram instagram.com/pepcoding/
Purani class yaad agyi sir! Awsm always!
Thanks a lot sumit bhai, bahot hi badhiya explanation. But ek baat samajh nai aa rhi ki itna mast lecture hone ke baad bhi views count kam kyo hai, soo sad
Aapne itna sahi explain kiya ki I am able to reduce the space complexity further, here is the code
The idea is once we found the island then to track whether this node is visited or not, we can mark current element as 0
public int numIslands(char[][] a) {
int count = 0;
int row = a.length;
int column = a[0].length;
for(int i = 0; i
For better experience, visit nados.io, where you will get well curated content and career opportunities.
Guru Ji yeh toh pure recursion ka question ho gaya. Recursion which is complex. GRAPH wali feeling nahi aayi isme.
But learnt a lot again about recursion
Keep learning and keep loving Pepcoding!😊
the way to teach is awesome, Thank you sir
Your content is amazing. It's helping me so much in interview preparation. Can you also include an explanation of time & space complexity in your future videos?
Noted
@@Pepcoding plz do atleast for some questions so we can have a idea of it ...
You are a great teacher sir.
i m easily able to relate to gold mine problem after this!🔥🔥
Your explanation sir love it♥
sir awesome explanation ... just a request kindly cover time and space complexity as well for the ques.
Glad to know that you liked the content and thank you for appreciating. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem.
Keep learning and keep loving Pepcoding😊
I have a doubt, suppose in above example used, in the rightmost island there is land i.e 0 in last row, left of last column.. So according to explanation that if the pointer goes to last column, it should return, then it won't check on left side of the rightmost-bottom 0, making a new island on left side, am I thinking right?
Best explanation 👍
Did this one with the backtracking method and got the answer
Time Complexity : O(m*n) and Space Complexity : O(m*n), If we don't use visited[m][n] and mark grid[m][n] to 1, so we can reduce space complexity.
Bhai mere ko time and space mein dikkat hoti hai Any resource to learn it
@@jobanpreetsingh2370 lot of sources you can find on web but most importantly when you solve the problem always try to understand it's logic,then easily you can able to find complexity. Just practice more and more.
you are awesome sir ji
This question can also be done using DSU Data structure.
Code->
class DSU {
public:
vector parent;
vector rank;
DSU(int v)
{
for(int i=0;irank[lv])
parent[lv]=lu;
else if(rank[lu]
Very nice explaination. Could you also discuss Time & Space complexity for all questions
Instead of having separate Boolean array for visited can't we have same input array and mark visited as 2. Then our space complexity would be O(1) , Correct me if I'm wrong...
But still we have recursion stack which will make space complexity O(N)...
we can do that, but ideally we shouldn't modify the original matrix as it's not a good practice. If your interviewer allows, then you can use this approach.
sir agar level up daal skte ho toh audience of 3rd and 4th years will join. this foundation is helpful for first and second yearites
han yar daalna hai. jaroor dalunga. thoda momentum bna rha hun. daalna to hai he hai
very good explanation, ur gem to me :)
love and support from Nepal sir :)
again visiting this after 10 months 😁
Some companies will asked why did you choose dfs instead of bfs? What should we answer in this case?
God of graphs
Sur please provide list for all questions to be done. Portal does not have many for sde-2
@pepcoding why dfs calls are not made for diagonal elements?
Great explaination sir 🙏
I am glad.
please make a video for Ford Fulkerson algorithm
sir solve tho ho gaya khud sey , samajh bhi ah gaya , but yeh samajh mai nahi aya yeh graph ka question kaise ? yeh tho recursion hai
best explanation sir .
Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
We need to add Diagonals moves as well for complete movement
void buildtree(vector& arr, vector& vis ,int i,int j){
if(i=arr[0].size()|| arr[i][j]=='0'||vis[i][j]==true){
return;
}
vis[i][j]=true;
buildtree(arr,vis,i-1,j);
buildtree(arr,vis,i,j+1);
buildtree(arr,vis,i,j-1);
buildtree(arr,vis,i+1,j);
buildtree(arr,vis,i+1,j+1);
buildtree(arr,vis,i+1,j-1);
buildtree(arr,vis,i-1,j-1);
buildtree(arr,vis,i-1,j+1);
}
int numIslands(vector &arr)
{
// Code here
int m=arr[0].size();
vector vis;
vector temp(m,false);
for(int i=0;i
great explanation Thank You!
Glad you enjoyed it!
Great Explanation Sir
Glad you liked it!! keep watching and share among your peers
awesome explanationcomplexity of this code will be O(m*n) right?
Thanks sir
great content sir.
Thankyou beta,
Keep learning and keep growing😊
Great explanation sir
Thanks for liking and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
@@Pepcoding Sir where can i find this code written by you for reference
Is sawaal ne itna pareshaan kiya h na kasam se . Leetcode mei alag condition , GFG mei alag condition aur yahan toh 1 k bajaye 0 land h .
Please discuss BFS approach also in some questions
ok ji
Thanks
Is tarah ka graph flood fill mei b diya gya tha na aur uss question mei basically humne dfs samjha tha is tarah k graph lete hue..aur is question mei hum log number of connected component nikal rha h same tarah k graph ko lete hue.. am I rit sir??
han beta wahi hai
I think we don't need to make top call correct me if wrong
For solving all your doubts you can post it on community tab of NADOS. For better experience and precisely arranged content you can visit on nados.io
Sir isme mujhe what and how samja par why? nai samja. And me ye video series me dekthe hue aaya tha... meko ye nai samja ki hume ye problem ko iss way me he kyu apporach kiya.
beta asal mei ye samjhna hai ki wo 2d matrix ke cell vertices hain aur edges unke beech hai. ye ek poori variety hai jisme graph aise 2d array ki form mei dia jata hai aur cells vertex ban jate hain. ek baar ye realise kar lia to question to sirf get connected component he tha.
agar aapko gcc ata hota aur ye dekhna ata hota to it was obvious. ab is tarah ke next questions mei aapke paas ye skill hogi.
Thank you sir..☺️
Sir kya aap level up questions list ko share kar sakte ho
isi list se question nikalung yar
docs.google.com/spreadsheets/u/1/d/1XdXJbn9NC7fx1CeavItkxR0Yos8rQAC9xXjnH4-f6Eg/edit#gid=0
Thank you sir
@@Pepcoding sir ye sare question jo apne share kiye hai.
Wo aap bhi level up course main covers karne wale hai sir..
thanks sir....
So nice of you and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
T-shirt achhi lag rahi he sir ye vali 😁
Je baat
Nice
Thanks
🔥🔥🔥🔥🔥🔥🔥🔥
sir vedios ki frequency kam hogayi hai, aap padhana chhod to nahi rahe ho online ?
aj dobara shuru ki hain. 4 videos bna chuka.
sir ye ques kam smaj aaya hai dobara bana dijiye video
Does anyone know why after iterating every we aren't marking visited[i][j] = true after line 26 ?
Sir very good explanation....But WHY are creating visited array we could just change the visited elements to water. 😁😁😁😁😁
Yes we can
Do u have a code link for this ?