I don't know how to thank you . We are paying money in lacs to college still they don't teach anything. But you are giving us these amazing explanation for free. Thank you so much brother. Keep making videos
I went over leetcode explanation, did not get it. Then i went over few of you tube videos where they just solved the question giving minimal explanation. Then i bumped on this. Thank you so much brother. I was trying to understand DFS practically and this pretty much sums it out for a beginner like me. Thanks a bunch again.
This is good explanation, suppose if going diagonally is also allowed . then will this work if we just add these 4 more directions to the existing 4 directions mark_current_island(matrix,x-1,y-1,r,c); // LEFT UP DIAGONAL mark_current_island(matrix,x-1,y+1,r,c); //RIGHT UP DIAGONAL mark_current_island(matrix,x+1,y-1,r,c); //LEFT DOWN DIAGONAL mark_current_island(matrix,x+1,y+1,r,c); //RIGHT DOWN DIAGONAL
@@techdose4u but you told in the video the time complexity as O(n). Since we are using dfs for each element, so the time complexity must be greater than O(nxm).What's your opinion? Please clarify it if i am wrong
@@abhishekjaiswal6492 asume if it's O(m*n) than N = m*n then complexity is O(N) which is again linear time so instead of writing O(m*n) we can directly say it's of O(n)
awesome bro... Another method I thought was to first find the indices of all the 1's and store it in list l. Then traverse through the list in dfs and keep on removing the elements from the list l if found ... But 😅one of the test case went out of time...46/47.
thank you so much! I love your teaching style. Although many RUclipsrs did algorithm videos, some of them started coding at first without exquisite explanations, so I can't follow them. Thank you again bro.
Thank you, I am so afraid to start any problem that I even couldn't sum two diagonal problem which is easiest. Having around 7 yr of experience as web developer but they way you explain and the code you show made me little confident that logic is most important in this problems
Java Code is below ============ public class NoOfIlands { public static void main(String[] args) { int noOfIlands = 0; int map[][]= {{1,1,0,0,0},{1,1,0,0,0},{0,0,1,0,0},{0,0,0,1,1}}; int height = map.length; int width = map[0].length;
Great Explanation. Here is the another code where we can process the current value and if it is island (1), we can make it water(0) directly and process all the adjacent nodes: public int numIslands(char[][] grid) { if(grid==null || grid.length==0) return 0; int landCount=0; /*for each and every value, check if it is 1 (island), then process all the adjacent (reachable ) nodes and make them 0 (water) and then increment the count of current island*/ for(int i=0;i
Sir , If grid contains all 1's then , complexity wiil be O(n* m) + O (complexity for the recursiver calls done in 1st iteration)... ? Will it be still O(n * m ).
Nice explanation sir.....your videos are really great....sir why the time complexity is o(n*m) what about the dfs call that we are making inside the two nested for loop...why it is not contributing into the time complexity?????? Please reply sir
I solved this question using my own method but the problem is runtime and memory is coming very high on leetcode, have a look and share your feedback class Solution { public : void dfs(int node,vector adj[],unordered_map &mpp) { for(auto itr:adj[node]) { if(mpp[itr]==0) { mpp[itr]=1; dfs(itr,adj,mpp); } } } public: int numIslands(vector& grid) { vector adj[grid.size()*grid[0].size()+1]; vector nodes; unordered_map mpp;//for visited. int count =1; int island=0; int flag=0; int singleFlag=0; char one='1'; for(int row=0;row
Earlier the condition I applied was if(i=row) ||j=column) || (grid[i][j]=='0')) But both condition are same only. Right. Oh. Sorry. Understood. It was counting 2 also. In tje the previous case
I don't know how to thank you . We are paying money in lacs to college still they don't teach anything. But you are giving us these amazing explanation for free. Thank you so much brother. Keep making videos
Thanks bro :)
well said man.
@@johnwick-gj9gb yup he deserves it
just say "T H A N K Y O U ! ! !" XD
in reality colleges have become randi khhana..u go and pick a girl
Your way of solving problems is easy to understand .. thank you for such a nice contents.
Welcome :)
I went over leetcode explanation, did not get it. Then i went over few of you tube videos where they just solved the question giving minimal explanation. Then i bumped on this. Thank you so much brother. I was trying to understand DFS practically and this pretty much sums it out for a beginner like me. Thanks a bunch again.
Welcome bro :)
Literally u made be this question a cake walk for me . Never studied DFS but your Clear voice filled with knowledge taught me everything
Great solution, and using the graph itself to store the visited state is a big brain move.
👍🏽
This is good explanation, suppose if going diagonally is also allowed . then will this work if we just add these 4 more directions to the existing 4 directions
mark_current_island(matrix,x-1,y-1,r,c); // LEFT UP DIAGONAL
mark_current_island(matrix,x-1,y+1,r,c); //RIGHT
UP DIAGONAL
mark_current_island(matrix,x+1,y-1,r,c); //LEFT DOWN DIAGONAL
mark_current_island(matrix,x+1,y+1,r,c); //RIGHT
DOWN DIAGONAL
I like your videos. You explain everything without skipping steps
I think the time complexity should be O(n * m) as we are traversing the whole matrix
Yes.
@@techdose4u but you told in the video the time complexity as O(n). Since we are using dfs for each element, so the time complexity must be greater than O(nxm).What's your opinion? Please clarify it if i am wrong
please reply
@@abhishekjaiswal6492 each recursive we will do maximum O( 1) work , so I think it's O(nm) , maybe it is > O(nm)
@@abhishekjaiswal6492 asume if it's O(m*n) than N = m*n then complexity is O(N) which is again linear time so instead of writing O(m*n) we can directly say it's of O(n)
In 2022. This video had a the best explanation for this problem, handsdown! :)
You explain way better than some youtubers with thousands subs. Thank you, dude! Keep doing
Thanks :)
That's an extraordinary explanation mate. You made it look so simple. Thanks a lot.
Welcome 😄
awesome bro...
Another method I thought was to first find the indices of all the 1's and store it in list l.
Then traverse through the list in dfs and keep on removing the elements from the list l if found ...
But 😅one of the test case went out of time...46/47.
Nice..... This technique is something different.
please make video on other graph algorithm.. your way of writing code and explaining is crystal clear.
Thanks...will do it soon
Thank you for this crystal clear explanation! I could not follow other explanations found on the internet, but this was very clear.
it was literally a crystal clear explanation for this question
thanku TechDose
u just made my day.....
thank you so much! I love your teaching style. Although many RUclipsrs did algorithm videos, some of them started coding at first without exquisite explanations, so I can't follow them. Thank you again bro.
Welcome :)
dude, you are the best teacher out there!!. Can call you as "Teacher" with out any spelling mistake!!
Thank you, I am so afraid to start any problem that I even couldn't sum two diagonal problem which is easiest. Having around 7 yr of experience as web developer but they way you explain and the code you show made me little confident that logic is most important in this problems
There are so many videos on youtube for this problem. Your explanation is the best 🍻
Thanks bro :)
Great explanation with simple and efficient solution.
really nice explanation is an easy efficient way thanks a lot
Welcome :)
nicely explained and presented, thank you.
good explanation, found a Indian programming tutorial gem :).
Thank you very much! You have a way of explaining things that makes it very easy to understand 👏🏾👏🏾
:)
Thanks, TechDOSE for this amazing graph series...thanks a lot...
Welcome
Waiting for disjoint set implementation of the above problem.
Btw Nice explanation! Thank you!!
Sure 👍🏼 Thanks
You always give us the best explanation, Thank you!!!
Welcome :)
THE BEST explaination.
Thanks :)
The best explanation. I have wasted 1 hour just by seeing other videos
Simply wow, one of the best solution.
Thanks :)
Very calm explanation
Thanks
You made this problem as easy as addition of two numbers!! Amazing explanation.
Thanks :)
OMG! Thanks!!!! Please Continue!!!!!!!!!!!!!!
The time complexity is O(m*n). Also it's better to use stack instead of recursion.
Great little tutorial, simplified the problem for me
Thanks 😄
Amazing level of explanation and speaking
Thanks
your explanation technique is awesome.
Thanks :)
No Words you are Awesome and Genius.. keep doing good problem vedios
Not genius...just consistent work :)
Your content is really good.
Easy to understand and it helps us to code based on that understanding.
Please continue making videos.
Thank you.
Welcome
Beautifully explained!! Thank you very much for this!
Welcome :)
Awesome Explanation Sir .
Thanks
it is a blessing to have found your channel
:) when did you find it actually?
TECH DOSE recently not sure exactly when 😄
You are AMAZING!!!! Best and Simple Explanation!! I am kinda falling short of words! 😀 Thanks Bro.
very nicely explained
i recently started watching referring your videos. This one is amazing. Such a clear and neat explanation! Thank you for this.
Welcome 😀
very clear, visual, and direct explanation. Thank you, bro.
Welcome :)
best teacher best youtuber thank you sir😃😊
Welcome :)
Java Code is below
============
public class NoOfIlands {
public static void main(String[] args) {
int noOfIlands = 0;
int map[][]= {{1,1,0,0,0},{1,1,0,0,0},{0,0,1,0,0},{0,0,0,1,1}};
int height = map.length;
int width = map[0].length;
for(int i=0;i
simple n best explanantion
:)
thanks for the amazing explanation. I was unable to find a good video but u explained very well.
excellent explanation
Thank you for very easy way explanations
Best explaination
Thanks :)
Great Explanation. Here is the another code where we can process the current value and if it is island (1), we can make it water(0) directly and process all the adjacent nodes:
public int numIslands(char[][] grid) {
if(grid==null || grid.length==0)
return 0;
int landCount=0;
/*for each and every value, check if it is 1 (island), then process all the adjacent (reachable ) nodes and make them 0 (water) and then increment the count of current island*/
for(int i=0;i
Nice thanks :)
Awesome ❤
Awesome Explanation. Thanks Sir!
wonderful explaination
I have a benefited a lot from your videos, keep up the good work!
Nice :)
Thank you, bro, for this clear explanation. 👍
Welcome :)
Short and concise 👌👌👌👌
👍🏼
Thanking you sir 😊☺️.. to make this problem easy to understand 😊
Welcome :)
Nice explanation. Thanks
Welcome
your content helping a lot.....Upload daily more and more problems❤
Thanks :)
Couldn't have been more clearer.Thanks for it :)
Welcome :)
Your explanation is no fire 🔥🔥🔥🔥🔥🔥
Thnaks sir today i take dose of this question😂😅😅😅
Thank you so much!! I finally understood the problem!
Wow! You use 2 which means we can restore grid. non zero is better than zero!
Best explanation
Thanku so much :)
Welcome :)
Sir really super amazing no words to express my happiness keep it up sir
Thanks :)
Awesome , top notch explanation. Thank you!
Sir , If grid contains all 1's then , complexity wiil be O(n* m) + O (complexity for the recursiver calls done in 1st iteration)... ? Will it be still O(n * m ).
Nice explanation sir.....your videos are really great....sir why the time complexity is o(n*m)
what about the dfs call that we are making inside the two nested for loop...why it is not contributing into the time complexity??????
Please reply sir
keep it up ..
welldone
Thanks :)
good explaination
Thank u so much , all thanks for the way you solve , very easy and understandable, really thanks a lot.
Welcome :)
great way of doing things ..awesome man
Thanks :)
Superb man! Thanks, for your help.
Welcome :)
I don't think checking left and up is necessary in mark_current_island method..
correct me if I am wrong..
well explained
The video was awesome but may i get list of questions of 30 days coding challenge
Excellent solution
Thanks :)
Our good deeds come back to us, I hope that someday I will be able to pay you for this wonderful explaination..........++Thankyou:)
😊
Excellent.. You explained it well...
Thanks :)
more specifically this is problem can be described as , find all of the connected component in the given graph.
True :)
Matlab bhai tum kaam 1 No. kar rahe ho...bas itna hi kehna chahta hun
Thanks bhai :)
good explanation
I solved this question using my own method but the problem is runtime and memory is coming very high on leetcode, have a look and share your feedback
class Solution {
public :
void dfs(int node,vector adj[],unordered_map &mpp)
{
for(auto itr:adj[node])
{
if(mpp[itr]==0)
{
mpp[itr]=1;
dfs(itr,adj,mpp);
}
}
}
public:
int numIslands(vector& grid) {
vector adj[grid.size()*grid[0].size()+1];
vector nodes;
unordered_map mpp;//for visited.
int count =1;
int island=0;
int flag=0;
int singleFlag=0;
char one='1';
for(int row=0;row
Thank you so much for a detailed explanation 🙂
Welcome :)
amazing explanation! thankyou
Welcome :)
Can not thank you enough for the wonderful explanation.
Welcome :)
Since we are traversing every value in the matrix then why the time complexity won't be O(N^2)??
Could you implement a bfs solution recursively as well?
Very Well expained sir ! thank you !
Welcome
Amazing explanation, sir 🙏
Thanks ☺️
To reach all the nodes of the land, why did you use dfs instead of bfs in the helper function?
Thanks a lot. Very neatly explained the logic . But i am getting stackoverflow exception when i implemented it.
Too many recursion calls. Maybe you forgot some base condition.
@@techdose4u Thanks a lot.
This condition worked.
if(i=row) ||j=column) || (grid[i][j]!='1'))
Earlier the condition I applied was
if(i=row) ||j=column) || (grid[i][j]=='0'))
But both condition are same only. Right.
Oh. Sorry. Understood. It was counting 2 also. In tje the previous case
Glad you made this video! great explanation.
Thanks
thnx u bro fir ur service
Welcome :)
@@techdose4u I really admire ur effort service u providing. God bless u my bro.
best explanation
Thanks :)
Nice Explanation : )
Thanks :)