Number of islands | Leetcode

Поделиться
HTML-код
  • Опубликовано: 23 ноя 2024

Комментарии • 378

  • @akshatjain6854
    @akshatjain6854 4 года назад +249

    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

    • @techdose4u
      @techdose4u  4 года назад +9

      Thanks bro :)

    • @johnwick-gj9gb
      @johnwick-gj9gb 4 года назад +4

      well said man.

    • @akshatjain6854
      @akshatjain6854 4 года назад +5

      @@johnwick-gj9gb yup he deserves it

    • @aakashkatiyar5005
      @aakashkatiyar5005 3 года назад +2

      just say "T H A N K Y O U ! ! !" XD

    • @pkyadav6230
      @pkyadav6230 2 года назад

      in reality colleges have become randi khhana..u go and pick a girl

  • @gauravsrivastavjsr
    @gauravsrivastavjsr 4 года назад +54

    Your way of solving problems is easy to understand .. thank you for such a nice contents.

  • @HarkiratSaluja
    @HarkiratSaluja 4 года назад +9

    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.

  • @devesh819
    @devesh819 Год назад

    Literally u made be this question a cake walk for me . Never studied DFS but your Clear voice filled with knowledge taught me everything

  • @redleader2211
    @redleader2211 Год назад +1

    Great solution, and using the graph itself to store the visited state is a big brain move.

  • @AruneshSrivastava
    @AruneshSrivastava 4 года назад +3

    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

  • @He_ze
    @He_ze 11 месяцев назад

    I like your videos. You explain everything without skipping steps

  • @hemantsood9579
    @hemantsood9579 4 года назад +60

    I think the time complexity should be O(n * m) as we are traversing the whole matrix

    • @techdose4u
      @techdose4u  4 года назад +13

      Yes.

    • @abhishekjaiswal6492
      @abhishekjaiswal6492 3 года назад +1

      @@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
      @abhishekjaiswal6492 3 года назад

      please reply

    • @abhishekshankar1136
      @abhishekshankar1136 3 года назад +1

      @@abhishekjaiswal6492 each recursive we will do maximum O( 1) work , so I think it's O(nm) , maybe it is > O(nm)

    • @eshaanbhat3732
      @eshaanbhat3732 3 года назад +3

      @@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)

  • @KarthikaRaghavan
    @KarthikaRaghavan 2 года назад

    In 2022. This video had a the best explanation for this problem, handsdown! :)

  • @beketmyrzanov1979
    @beketmyrzanov1979 4 года назад +7

    You explain way better than some youtubers with thousands subs. Thank you, dude! Keep doing

  • @shritishaw7510
    @shritishaw7510 2 года назад +14

    That's an extraordinary explanation mate. You made it look so simple. Thanks a lot.

  • @saurabhsengar9520
    @saurabhsengar9520 4 года назад +6

    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.

    • @techdose4u
      @techdose4u  4 года назад +2

      Nice..... This technique is something different.

  • @shishpalvishnoi7974
    @shishpalvishnoi7974 4 года назад +2

    please make video on other graph algorithm.. your way of writing code and explaining is crystal clear.

    • @techdose4u
      @techdose4u  4 года назад

      Thanks...will do it soon

  • @davidalexander2058
    @davidalexander2058 2 года назад +1

    Thank you for this crystal clear explanation! I could not follow other explanations found on the internet, but this was very clear.

  • @snehasoni1392
    @snehasoni1392 7 месяцев назад

    it was literally a crystal clear explanation for this question
    thanku TechDose
    u just made my day.....

  • @luobohu8128
    @luobohu8128 4 года назад +3

    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.

  • @stupify6751
    @stupify6751 Год назад

    dude, you are the best teacher out there!!. Can call you as "Teacher" with out any spelling mistake!!

  • @saurabhchauhan232
    @saurabhchauhan232 3 года назад

    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

  • @spetsnaz_2
    @spetsnaz_2 4 года назад +3

    There are so many videos on youtube for this problem. Your explanation is the best 🍻

  • @AshwaniSharma-of2nq
    @AshwaniSharma-of2nq 2 года назад

    Great explanation with simple and efficient solution.

  • @rohitchauhan6170
    @rohitchauhan6170 2 года назад +1

    really nice explanation is an easy efficient way thanks a lot

  • @RajeshS-n2j
    @RajeshS-n2j 2 месяца назад

    nicely explained and presented, thank you.

  • @QuantumTick
    @QuantumTick 3 года назад +2

    good explanation, found a Indian programming tutorial gem :).

  • @KevinN44
    @KevinN44 3 года назад +3

    Thank you very much! You have a way of explaining things that makes it very easy to understand 👏🏾👏🏾

  • @ritikbhardwaj4061
    @ritikbhardwaj4061 4 года назад +4

    Thanks, TechDOSE for this amazing graph series...thanks a lot...

  • @sajidali_6567
    @sajidali_6567 3 года назад +3

    Waiting for disjoint set implementation of the above problem.
    Btw Nice explanation! Thank you!!

  • @Jeremy-yb5yo
    @Jeremy-yb5yo 4 года назад +3

    You always give us the best explanation, Thank you!!!

  • @kumarpallav8156
    @kumarpallav8156 3 года назад +5

    THE BEST explaination.

  • @kirthe1116
    @kirthe1116 Год назад

    The best explanation. I have wasted 1 hour just by seeing other videos

  • @sohamdey2177
    @sohamdey2177 3 года назад +1

    Simply wow, one of the best solution.

  • @avadhootjoshi1805
    @avadhootjoshi1805 3 года назад +1

    Very calm explanation

  • @shivangishukla2629
    @shivangishukla2629 4 года назад +4

    You made this problem as easy as addition of two numbers!! Amazing explanation.

  • @peter-eh2oq
    @peter-eh2oq 2 года назад

    OMG! Thanks!!!! Please Continue!!!!!!!!!!!!!!

  • @sergeykodzha2621
    @sergeykodzha2621 Год назад

    The time complexity is O(m*n). Also it's better to use stack instead of recursion.

  • @robertyoungie
    @robertyoungie 2 года назад +1

    Great little tutorial, simplified the problem for me

  • @Siddharth-yi7pg
    @Siddharth-yi7pg 3 года назад +1

    Amazing level of explanation and speaking

  • @harshpatel1385
    @harshpatel1385 4 года назад +1

    your explanation technique is awesome.

  • @naveenkumar-ns9sg
    @naveenkumar-ns9sg 4 года назад +1

    No Words you are Awesome and Genius.. keep doing good problem vedios

    • @techdose4u
      @techdose4u  4 года назад

      Not genius...just consistent work :)

  • @aniketwattamwar1514
    @aniketwattamwar1514 3 года назад +2

    Your content is really good.
    Easy to understand and it helps us to code based on that understanding.
    Please continue making videos.
    Thank you.

  • @kercat89
    @kercat89 4 года назад +3

    Beautifully explained!! Thank you very much for this!

  • @kartikbadnorejain4708
    @kartikbadnorejain4708 3 года назад +1

    Awesome Explanation Sir .

  • @575saisri4
    @575saisri4 4 года назад +2

    it is a blessing to have found your channel

    • @techdose4u
      @techdose4u  4 года назад

      :) when did you find it actually?

    • @575saisri4
      @575saisri4 4 года назад

      TECH DOSE recently not sure exactly when 😄

  • @rumaroy219
    @rumaroy219 2 года назад

    You are AMAZING!!!! Best and Simple Explanation!! I am kinda falling short of words! 😀 Thanks Bro.

  • @sahildadhich59
    @sahildadhich59 5 месяцев назад

    very nicely explained

  • @radhu8
    @radhu8 3 года назад +6

    i recently started watching referring your videos. This one is amazing. Such a clear and neat explanation! Thank you for this.

  • @CengizAkarsu
    @CengizAkarsu 3 года назад +1

    very clear, visual, and direct explanation. Thank you, bro.

  • @bestdeal3385
    @bestdeal3385 2 года назад +1

    best teacher best youtuber thank you sir😃😊

  • @Venkat.devisetti
    @Venkat.devisetti 3 года назад +1

    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

  • @RajatAsthana24
    @RajatAsthana24 19 дней назад

    simple n best explanantion

  • @varunajmera
    @varunajmera 2 года назад

    thanks for the amazing explanation. I was unable to find a good video but u explained very well.

  • @rroy2812
    @rroy2812 3 года назад

    excellent explanation

  • @openworld7585
    @openworld7585 4 года назад

    Thank you for very easy way explanations

  • @shirish2005
    @shirish2005 Год назад +1

    Best explaination

  • @cseinterviewprep6182
    @cseinterviewprep6182 4 года назад +1

    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

  • @saimeghanabarla9646
    @saimeghanabarla9646 Год назад

    Awesome ❤

  • @ChandanKumar-em8zg
    @ChandanKumar-em8zg 2 года назад

    Awesome Explanation. Thanks Sir!

  • @ManinderSingh-xr6ir
    @ManinderSingh-xr6ir Год назад

    wonderful explaination

  • @christophermcmahon9541
    @christophermcmahon9541 Год назад +1

    I have a benefited a lot from your videos, keep up the good work!

  • @skypravda
    @skypravda 3 года назад +2

    Thank you, bro, for this clear explanation. 👍

  • @vivek.tiwary
    @vivek.tiwary 3 года назад +1

    Short and concise 👌👌👌👌

  • @kunalsoni7681
    @kunalsoni7681 4 года назад +1

    Thanking you sir 😊☺️.. to make this problem easy to understand 😊

  • @sunilthind3257
    @sunilthind3257 4 года назад +1

    Nice explanation. Thanks

  • @ManishKumar-ys5oj
    @ManishKumar-ys5oj 4 года назад +4

    your content helping a lot.....Upload daily more and more problems❤

  • @decodingParinda
    @decodingParinda 4 года назад +1

    Couldn't have been more clearer.Thanks for it :)

  • @ashisbhowmik348
    @ashisbhowmik348 3 года назад +1

    Your explanation is no fire 🔥🔥🔥🔥🔥🔥

  • @Highlights_Point
    @Highlights_Point 2 года назад +1

    Thnaks sir today i take dose of this question😂😅😅😅

  • @poojakhatri4426
    @poojakhatri4426 2 года назад

    Thank you so much!! I finally understood the problem!

  • @mingxiao1939
    @mingxiao1939 3 года назад

    Wow! You use 2 which means we can restore grid. non zero is better than zero!

  • @kannupriyasingh
    @kannupriyasingh 3 года назад +2

    Best explanation
    Thanku so much :)

  • @malkarajk4093
    @malkarajk4093 4 года назад +2

    Sir really super amazing no words to express my happiness keep it up sir

  • @MP-ny3ep
    @MP-ny3ep 2 года назад

    Awesome , top notch explanation. Thank you!

  • @AnkushKumar-mk8ns
    @AnkushKumar-mk8ns 4 года назад +2

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

  • @paragroy5359
    @paragroy5359 3 года назад +1

    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

  • @abhaytiwari6411
    @abhaytiwari6411 4 года назад +2

    keep it up ..
    welldone

  • @apcs914
    @apcs914 Год назад

    good explaination

  • @AbhayKumarAgrawal
    @AbhayKumarAgrawal 4 года назад +2

    Thank u so much , all thanks for the way you solve , very easy and understandable, really thanks a lot.

  • @johnwick-gj9gb
    @johnwick-gj9gb 4 года назад +1

    great way of doing things ..awesome man

  • @shikharjaiswal6877
    @shikharjaiswal6877 3 года назад +1

    Superb man! Thanks, for your help.

  • @keshavsingh9864
    @keshavsingh9864 3 года назад

    I don't think checking left and up is necessary in mark_current_island method..
    correct me if I am wrong..
    well explained

  • @jay-rathod-01
    @jay-rathod-01 3 года назад

    The video was awesome but may i get list of questions of 30 days coding challenge

  • @MirzaTalks36
    @MirzaTalks36 4 года назад +1

    Excellent solution

  • @sgr2683
    @sgr2683 3 года назад +1

    Our good deeds come back to us, I hope that someday I will be able to pay you for this wonderful explaination..........++Thankyou:)

  • @manuramvelappan5935
    @manuramvelappan5935 4 года назад +1

    Excellent.. You explained it well...

  • @Amit_Kumar_1999
    @Amit_Kumar_1999 4 года назад +7

    more specifically this is problem can be described as , find all of the connected component in the given graph.

  • @ravikumarmathanya5369
    @ravikumarmathanya5369 3 года назад +1

    Matlab bhai tum kaam 1 No. kar rahe ho...bas itna hi kehna chahta hun

  • @atultiwari1547
    @atultiwari1547 4 года назад

    good explanation

  • @mohdhammadsiddiqui7598
    @mohdhammadsiddiqui7598 2 года назад

    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

  • @journeytowardslife9830
    @journeytowardslife9830 3 года назад +1

    Thank you so much for a detailed explanation 🙂

  • @tanyamalhotra9505
    @tanyamalhotra9505 2 года назад +1

    amazing explanation! thankyou

  • @RohitSharma-bu6lc
    @RohitSharma-bu6lc 4 года назад +1

    Can not thank you enough for the wonderful explanation.

  • @pritam7461
    @pritam7461 2 года назад

    Since we are traversing every value in the matrix then why the time complexity won't be O(N^2)??

  • @Tzone02
    @Tzone02 Год назад

    Could you implement a bfs solution recursively as well?

  • @santerek28
    @santerek28 4 года назад +1

    Very Well expained sir ! thank you !

  • @mehulagarwal6063
    @mehulagarwal6063 3 года назад +1

    Amazing explanation, sir 🙏

  • @codeblooded6760
    @codeblooded6760 2 года назад

    To reach all the nodes of the land, why did you use dfs instead of bfs in the helper function?

  • @AdvayaKala
    @AdvayaKala 4 года назад +1

    Thanks a lot. Very neatly explained the logic . But i am getting stackoverflow exception when i implemented it.

    • @techdose4u
      @techdose4u  4 года назад

      Too many recursion calls. Maybe you forgot some base condition.

    • @AdvayaKala
      @AdvayaKala 4 года назад

      @@techdose4u Thanks a lot.
      This condition worked.
      if(i=row) ||j=column) || (grid[i][j]!='1'))

    • @AdvayaKala
      @AdvayaKala 4 года назад

      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

  • @harshitsxxd
    @harshitsxxd 4 года назад +1

    Glad you made this video! great explanation.

  • @tannubajpai4782
    @tannubajpai4782 2 года назад +1

    thnx u bro fir ur service

    • @techdose4u
      @techdose4u  2 года назад +1

      Welcome :)

    • @tannubajpai4782
      @tannubajpai4782 2 года назад

      @@techdose4u I really admire ur effort service u providing. God bless u my bro.

  • @anybodycancode5093
    @anybodycancode5093 4 года назад +1

    best explanation

  • @komirisrinathgoudkomiri1534
    @komirisrinathgoudkomiri1534 3 года назад +1

    Nice Explanation : )