G-51. Number of Islands - II - Online Queries - DSU

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

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

  • @takeUforward
    @takeUforward  2 года назад +31

    Let's continue the habit of commenting “understood” if you got the entire video. Please give it a like too,.
    Do follow me on Instagram: striver_79

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

      understood

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

      very hard working bhaiyaaa😮‍💨🥵

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

      you are literally the best teacher anyone can get,I feared DSA so much since my basics were weak thanks a lot your videos are super addictive,I have actually started liking DSA,in college used to hate it :)

    • @KiranKumar-sb3ti
      @KiranKumar-sb3ti 4 месяца назад

      understood

  • @gowthamsivam2210
    @gowthamsivam2210 Год назад +5

    The Kind of Excitement you show in your face while explaining.

  • @ashishkumaryadav5252
    @ashishkumaryadav5252 Год назад +43

    Sir, your explanations skills are exceptional, i bought an unacademy course but comparatively your explanations are far better than that paid course, really there is no sense of paying any DSA course online if your videos are available.

  • @tanyacse6577
    @tanyacse6577 2 года назад +74

    Hi striver
    I am final year student I watch your content from my second year
    turst me I follow lot of content and also purchase course on DSA and i didn't clear my concept
    when i saw your Amazing DP Playlist and graph ,recursion it just 🔥
    I just advice my junior of college to watch your content
    your content was literally bro amazing
    I just want to tell that in u way solved the various question/ problem it just clear all the topic in that way of minute
    u r amazing please never stop doing this it's really hlep alot people with such a content
    and aslo I cracked amazon recently
    Thanks to you to provide such a amazing content
    Thank you so much🔥🔥🔥🔥🔥

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

      hey can you share the questions that were asked you during the interview rounds and in OA

    • @dhirendrasingh6071
      @dhirendrasingh6071 Год назад +4

      Amazon wow program...

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

      Hi maam , aap kis college se hai . kya aap mujhe kuch guide kr skti hai currently i am in second year student .

  • @sanskarkumar6391
    @sanskarkumar6391 2 года назад +21

    This question was asked to one of my friend in thoughtspot round 1 interview for SDE Intern role.

  • @Ani_86_
    @Ani_86_ 2 года назад +8

    The explanation was perfect and also this problem marks the beginning of dsu in matrices !!

  • @ayushm106
    @ayushm106 Год назад +6

    Understood. Thanks for laying emphasis on Code Quality

  • @debugger275
    @debugger275 Год назад +12

    Understood !!!
    This series is Gem Mine 🙌🙌 thank you for your hard work

  • @varunaggarwal7126
    @varunaggarwal7126 Год назад +2

    his explanation drew an image in my brain, I was able to code that in 1 go.

  • @vishalsinghrajpurohit6037
    @vishalsinghrajpurohit6037 Год назад +10

    There is one more way of doing it. By manipulating the DSU snippet. Initializing parent array with -1 and making parent[node]=node when we iterate the operators array.
    The space complexity is little lesser as we don't always need to initialize the visit and parent array of size (n*m). Instead we are initializing it with size of operators.size().
    But the way striver Bhai has written and explained is clean. Here is my code..
    class DisjointSet{

    public:
    vectorrank,parent,size;
    DisjointSet(int n){
    rank.resize(n+1,0);
    for(int i=0;i

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

      Thanx vishal for sharing your approach

    • @FooBar-lb5wf
      @FooBar-lb5wf 2 месяца назад

      This approach feels more natural and intuitive. Since each query effectively adds one cell land mass to the graph, the total land mass after Q queries would be atmost Q (considering the possibility of duplicate queries). The adjacency of two land cells on the matrix then corresponds to edges connecting those cells (and their components in the DS). The interal state of DS also more accurately captures the true number of components at each step, as opposed to the approach presented in the video where internal state of DS treats singleton water cells as components as well.

  • @stith_pragya
    @stith_pragya 11 месяцев назад +1

    Understood........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻.
    Before I checked the complete video, I just watched the video till 6:00 and was able to derive the complete solution by myself........😀😀😀😀😀😀...........This increases confidence.....😎😎😎😎😎😎.
    Thanks a lot Striver Brother.........You are doing a very great job......God Will surely bless you.........😇😇😇😇😇😇

  • @yadneshkhode3091
    @yadneshkhode3091 2 года назад +12

    Thank you for your relentless hardwork even on Diwali ❤️😊❤️😊
    Happy Diwali !

  • @stith_pragya
    @stith_pragya 11 месяцев назад +2

    Thank You So Much for this wonderful video.......................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

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

    Understood! Super excellent explanation as always, thank you very much!!

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

    initially, initialize the visited array by 0, and make a count variable to store the number of island groups.
    1) pickup querie that is(row,column) in the given operations.
    2) check whether Querie is visited or not visited::
    => If it is not visited mark it as visited and make the count increase by 1, then go for its neighbors
    if a neighbor is found to have 1 then connect the previous neighbor to the new neighbor by dsu,
    and decreases the count by 1 as connections form and add to our ArrayList.
    => If it is visited then store the same count in the list.initially, initialize the visited array by 0, and make a count variable to store the number of island groups.
    1) pickup querie that is(row,column) in the given operations.
    2) check whether Querie is visited or not visited::
    => If it is not visited mark it as visited and make the count increase by 1, then go for its neighbors
    if a neighbor is found to have 1 then connect the previous neighbor to the new neighbor by dsu,
    and decreases the count by 1 as connections form and add to our ArrayList.
    => If it is visited then store the same count in the list.

  • @SD-vk3ko
    @SD-vk3ko 2 года назад +3

    Thank you so much for the effort. I request to please add a lecture on Minimize Malware Spread or Minimize Malware Spread 2 problem also. These are kind of unique patterns of Union Find.

  • @vamsikrishnagannamaneni912
    @vamsikrishnagannamaneni912 2 месяца назад

    The reason for using Union instead of decrementing island count on every directional match :
    If the upper direction already merged two islands into one, the left direction won't contribute further because the union(u, v) function will check the updated ultimate parents of the two cells. If they now share the same parent, it returns False, preventing any redundant merging and maintaining the correct island count.

  • @raghavmanish24
    @raghavmanish24 3 месяца назад

    understood ......very close to finish this series....thanku striver

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

    excellent explanation!! application of disjoint set data structure explained nicely..Thanks

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

    U r the best teacher 🙏

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

    Understood!!
    I wish I started watching your videos earlier when I was learning tree and stuff man

  • @augustinradjou3909
    @augustinradjou3909 9 месяцев назад

    Amazing boss....going to complete the series soon❤

  • @UECAshutoshKumar
    @UECAshutoshKumar 11 месяцев назад +1

    Thank you sir 😊

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

    i coded myself sir. such a nice feeling for me.

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

    @takeUforward please share the time complexities as you did in the previous videos.

  • @sourabhgautam4809
    @sourabhgautam4809 2 года назад +2

    Time complexity = O(k*4*4*alpha) where k = operators.size();

  • @ajitpalsingh606
    @ajitpalsingh606 4 месяца назад

    Question was very logical ... congrats for 0.6 Million subscribers striver !!

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

    I was just stuck on "most-stones-removed-with-same-row-or-column" Ah I wish I had say your video earlier... 2d UnionFind is tough to undertstand!

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

    Understood.... Amazing Explanation🙌🙌

  • @Chandraprakash-kx4ic
    @Chandraprakash-kx4ic Год назад

    Understood. Thank YOU, STRIVER. Immense love and respect dude💋💋

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

    Understood. Hats off to you

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

    understood great approach striver.

  • @netviz8673
    @netviz8673 Месяц назад

    Disjoint set: Dynamic Graph and Connections and Connections

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

    Understood bhaiya 🙏❤️

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

    We can also use arr[pos/rows][pos%rows]

  • @SatyamKumar-bw4vi
    @SatyamKumar-bw4vi Год назад

    Hare Krishna..! understood

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

    Understood, Great explanations

  • @Sc0tchx0P
    @Sc0tchx0P Год назад +4

    understanding approach is so easy but when it comes to coding it on my own I get stuck for hours

  • @chaotichally
    @chaotichally 9 месяцев назад +1

    Can I consider only the coordiantes given in the input as nodes and count the no of connected components at each step ??

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

    What an explanation man !👏👏

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

    thank you sir for a lot of effort for us

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

    Thanks Striver!

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

    understood,awesome explanation

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

    I always eagerly wait for your videos.

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

    If someone say you can't do anything in life ,show them 4:25 ,move on and work hard.

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

    You are a GEM!! Thank you very much

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

    "understood" 🙂

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

    East or West , Striver is the best😍,BST Series❤‍🔥 Graph❤‍🔥

  • @rushhour4379
    @rushhour4379 6 месяцев назад

    If the path compression is not updated according to the latest unions, it is not safe to compare parents before compressing right? It might not always return latest ultimate parent. What is the idea behind comparing without ensuring compression? Am I missing something?

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

    understood sir

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

    Awesome explanation🔥🔥🔥

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

    OP Explanation 🔥

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

    Amazing as always! Thanks a ton!!!

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

    Understood thanks a lot 👍

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

    Understood as always 😃

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

    Thank you 🙏

  • @prateek4279
    @prateek4279 6 месяцев назад

    this was a tough one

  • @-NagumantryRaghuveer
    @-NagumantryRaghuveer Год назад

    Too good
    Understood

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

    Superb

  • @adebisisheriff159
    @adebisisheriff159 10 месяцев назад

    Understood!

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

    Thanks🙌

  • @vaibhavagarwal1479
    @vaibhavagarwal1479 10 месяцев назад

    Can someone help me with this
    why here memset work
    int vis[n][m];
    memset(vis,0, sizeof vis);
    where as
    int vis[n][m] = {0};
    doesn't work for test case 23 aren't both the code serving same purpose?

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

    Understood 🔥🔥

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

    understood 💖💖💖💖💖

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

    Understood.

  • @vishalbairagi5364
    @vishalbairagi5364 4 месяца назад

    thanks boss

  • @evilpollination1916
    @evilpollination1916 6 месяцев назад

    understood.

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

    Understood❤

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

    helpful

  • @Aryan-vw7lt
    @Aryan-vw7lt Год назад +1

    understooddddd

  • @vishnu9134
    @vishnu9134 9 месяцев назад

    understood🤩

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

    Nice

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

    Understood!!

  • @ACUCSPRADEEPB-up9ne
    @ACUCSPRADEEPB-up9ne Год назад

    Understood✌️

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

    time complexity?

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

    understoodd

  • @1tav0
    @1tav0 Год назад

    understood!!!

  • @krishnendu-jana
    @krishnendu-jana Год назад +1

    Nokia Algorithm - "Connecting People(Island) 😶"

  • @jessepinkman2231
    @jessepinkman2231 2 месяца назад

    can we solve this question just like the most stones removed with same row or column approach if anyone knows or have an idea about it pls do reply thanks in advance

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

    understood!

  • @nizh3278
    @nizh3278 23 дня назад +1

    Anyone who asks me how to start dsa i tell them watch striver😂

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

    understood🔥🔥🔥

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

    understood💯

  • @KapilMaan-vw9sd
    @KapilMaan-vw9sd 3 месяца назад

    understood sir 🩷

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

    Understood:)

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

    Understood

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

    understood

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

    Striver OP

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

    great

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

    Link for this problem on GFG?

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

    🎉🎉🎉🎉🎉🎉

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

    Loved the explaination !!

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

    How many videos will be there in this graph playlist

  • @HarshSharma-jd4cc
    @HarshSharma-jd4cc Год назад

    alternate solution using pairs: ig better to read!
    // User function Template for C++
    class Solution {
    public:
    class DisjointSet{
    public:
    vector rank;
    vector parent;
    DisjointSet(int n , int m ){
    rank = vector(n,vector(m,0));
    parent = vector(n,vector(m,{0,0}));
    for(int i =0 ; i

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

    US

  • @Abhishekkumar-im7lb
    @Abhishekkumar-im7lb Год назад

    Why can't we use parent array for finding parent instead of findparent function.
    When we use unionByrank or size ,we are assigning ultimate parents to nodes,then parent array should give us ultimate parent ?

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

      I also had the same doubt but no ! consider this ds where 1 3 5 are connected now there's another ds 6 7 so 7's parent is 6 right? but when we connect this ds with the prior ds 7's parent is still not changed the only change in the parent is of 6 and 7's parent still remains 6 . So consider the possibility that there are tons of nodes. It would fail. I hope this clears up. Please correct me if I'm wrong.

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

    unionbyrank is not working in this question. if anyone know the reason please reply

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

      Union by rank is just an optimization to the disjoint set algorithm. You must be missing something. Can you post your code down here?

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

      bro code is working absolutly fine i think u made some mistake in union by rank function. drop your code maybe we can help u.

  • @051-avnee4
    @051-avnee4 Год назад

    US :)) !!!!!!

  • @mrcoder-o3g
    @mrcoder-o3g Год назад

    Can any one help me to figure out what mistake I have done over here
    int fun1(int u,vector&parent){
    if(u==parent[u]){
    return u;
    }
    return parent[u]=fun1(parent[u],parent);
    }
    void union1(int u,int v,vector&rank,vector&parent){
    int parentU=fun1(u,parent);
    int parentV=fun1(v,parent);
    if(parentU==parentV)
    {
    return;
    }
    else if(rank[parentU]==rank[parentV]){
    parent[parentU]=parentV;
    rank[parentV]++;
    }
    else if(rank[parentU]>rank[parentV]){
    parent[parentV]=parentU;
    }
    else
    {
    parent[parentU]=parentV;
    }
    }
    vector numOfIslands(int n, int m, vector &operators) {
    // code here
    int i,j;
    vector parent(n*m,0);
    vector rank(n*m,0);
    vector vis(n,vector(m,0));
    vector ans;
    for(i=1;i

  • @arvindjaiswal8013
    @arvindjaiswal8013 4 месяца назад

    When he drew with the red pen on the grid for the last two queries, what was drawn will make you laugh. 😆 😆
    Comment understood if you really did. 🤪🤪

    • @thaman701
      @thaman701 4 месяца назад

      Ling ban gya tha.😂

    • @thaman701
      @thaman701 4 месяца назад

      Bhai ek baat bata to is qs m hamne row*m + col kia h pr humne numbering to di hi ni h matrix ko to kaise pta lagega konsa cell h krke

    • @arvindjaiswal8013
      @arvindjaiswal8013 4 месяца назад

      @@thaman701 , aapko query me sabhi nodes ke coordinates diye hote hain... Unhi coordinates se aapko cell number nikalna hota hai

    • @thaman701
      @thaman701 4 месяца назад

      @@arvindjaiswal8013 bhai aap graphs ke algorithm ko revise krte ho kya or krte ho to kaise krte ho kitne kitne din m

    • @arvindjaiswal8013
      @arvindjaiswal8013 4 месяца назад

      ​@@thaman701, nhi main abhi seekh hi rha hun... Striver ke videos se kafi kuch seekhne ko mila... Isi ke playlist se DP bhi seekhi... Kunal Kushwaha ke videos se Tree and baki data structures seekhe... Sabhi ko local IDE pe code karke usme proper comments daal daal ke rakha hun... Abhi 2 maheene hue hain sab seekhte hue... Revise krne ka time nhi Mila abhi kyuki abhi system design bhi seekhna hai... Waise mujhe kam time lagega kyuki Mai 8 sal ka experienced hun...