Google Coding Interview Question and Answer - Most Stones Removed with Same Row or Column [LeetCode]

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

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

  • @vinceluu
    @vinceluu 3 года назад +21

    Found your channel during my leetcode prep for interviews, super concise and clear explanations! Please keep uploading solutions!

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

      Thanks Vince! I’m working on a new one. Hopefully will be up in a week or so.

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

    Best channel to learn how to solve questions in competitive coding systematically.

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

    Crazy Insaan!! you are great.
    The way you solve and boil down to a simple formula and make the question so so easy is so insan now i am fan of your hats off to you skills

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

    Thanks for an amazing explanation.
    1. when you showed how the first example will work in a grid by removing the stones from 1.12 onwards, you are removing in the same order as if you remove the leaves from its spanning tree. how to actually go there? if we remove randomly matching stones, it wont end up with just 1 stone.
    2. why the worst case complexity of naive solution is O(n2logn) if the amortized complexity of union-find is a constant: shouldn't the complexity be O(n2)?
    3. what is the complexity of the final solution?

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

    Amazing explanation. The diagram you used to explain made it really simple to understand.

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

    Your Explanations are just so great - To the point - No beating around the bush and extremely helpful. But you stopped making videos :(
    More power to you and may we find more such videos
    Admiration from India

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

      Thanks Aadarsh! I didn’t stop, I’ve been extra busy lately but will post more soon :)

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

    I hope you are doing well. This is so great explanation! Keep Uploading and keep Shining!

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

    @Shiran Afergan There is so much clarity in your explanation! Superb.

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

      Thanks Jaideep! I’m glad you enjoyed it :)

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

      Cheers from India. Looking forward to more such awesome content.

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

    The way of explanation with visual effects is too good, Thanks for the video 😊

  • @AnshulSharma-gq2vn
    @AnshulSharma-gq2vn Год назад

    Very well explained Shiran!! Kudos!

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

    I really enjoyed your explanation and the clean code you write, I am prepping for google interview next week, your channel came to me at the right time via leetcode discuss forum :) please keep making more videos

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

      Working on it :) best of luck with your interview! 💪🏽

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

    You are very Fluent and like the visualization Thanks for the hard work

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

    These videos deserve more views!

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

    Oh lord how I have struggled with this problem, where have you been

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

    Thank you for your videos and content stumbled across this video looking for union find solution to this problem. I hope you continue to upload videos and content!

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

    Great explanation !! I really liked the way you explain the problem from scratch : ) Subscribed...

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

    Astonish! thanks for your hard work

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

    Amazing explanation ! Please keep making videos !

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

      Thank you 😊 I’m working on it :)

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

    Explanation is really awesome.

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

    Elegant solution. You have got a new subscriber :)

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

      Thanks Akshay! I’m glad you liked it :)

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

    Splendid Explanation !

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

    Hey .. awesome explanation. Subscribed for easy explanation. Keep up the good work. Can you please do a videos on problem : region cut by slashes.

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

      I am also looking for solution of this problem.

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

      Thank you! Since it is also a union find question, it might take some time (i wanna do some tree, graph and recursion questions first) but seems interesting, thanks! ☺️

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

    What an amazing explanation !!!!

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

    Awesome plz continue series with Google questions

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

    awesome explanation thank you.. keep making videos

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

    OMG ur very good at explaining

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

      Thank you! I’m glad you liked it :)

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

    Awesome video. How can you be so good at this? Keep posting please.

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

      Thanks Jiadong! You just need to practice :)

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

    Loved your explanation! thanks

  • @Victoria-dk2jm
    @Victoria-dk2jm 2 года назад +1

    Perfect explanantion !!

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

    Explained so well.

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

    I have been going through all you videos in the list . Thanks for sharing all the knowledge .
    I couldn't understand how groups were created inside a constructor of union find , like in example 6 groups are created upfront . I understand union like maintain parent as : (item index , parent value) . But couldn't really visualize when item itself is combination of two numbers.

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

      But I got it now , item is row and column individually and instead of indexing with array which we have generally use , we have a map also we don't care about stone but only its cordinates . Being from java background parent[col] gave me feeling of index instead of keys .

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

      I can see why it’s confusing:) I now code in Java in my job and I keep trying to use [] with maps and don’t understand why it’s not working 🙃

  • @chris.w391
    @chris.w391 3 года назад +1

    Thank you! Well explained.

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

    It was superb ..... can you suggest how to come up with such way of solving how you thought of this problem. Can you suggest some good resources to study for interviews

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

      Thanks Aditya! I plan on doing a video with tips on how to approach such problems and maybe a series on data structures and common algorithms.
      For practicing I recommend LeetCode and GeeksforGeeks.

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

      @@ShiranAfergan +1

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

    great explanation! :)

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

    thank you, great explanation

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

    Really nice explanation

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

    Awesome explanation !! Can you please tell what is the drawing tool that you use ? I was thinking of using some kind of drawing tool for my virtual interviews.

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

    Hi, why have you added 1 to row and column.

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

    Good explanation

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

    can you make a video on this leetcode.com/problems/accounts-merge/ and can you more graph problems like this video. this video was very good. thanks

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

      Thanks Ritwik! I like your suggestion, i will add this question to my list. I think the next one is going to be “robot room cleaner”. Hope you enjoy it :)

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

      @@ShiranAfergan thanks a lot

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

    It really helped ! Thanks a lot

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

    Why rank was not updated during merging in rest 2 conditions ?

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

    great explanation

  • @DharmendraYadav-sf4ti
    @DharmendraYadav-sf4ti 4 года назад +1

    Nice Explanation

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

    I am unable to understand what does count variable stores initially, can we do count = stones. size(); as well

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

      count will store the number of groups we have intially
      No, you can not do count = stones. size() this will be wrong
      just think over this example: [ [0, 0], [1,1], [2,2] ]
      here:
      count = stones. size() = 3 [WRONG]
      count = parent.size() = 6 [row0, col0, row1, col1 like that] [ CORRECT]

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

    amazing explanation, thanks a lot, I have a doubt- when rank[xset]

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

      Thanks:) it’s not an error because you only care about the rank of the root (the representative of the set) and yset is now under xset so we only need to update the rank of xset

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

    Watched that video again, and I was about to comment when I saw that I already did a year ago haha :P

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

      Haha hope you enjoyed it the second time as well 😄

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

      @@ShiranAfergan I did for sure :)

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

    amazing! thank you

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

      I’m glad you liked it :) thanks for watching.

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

    You are beautiful ;) Btw Thanks for the explanation😊

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

      Thanks and you’re welcome :) glad it helped

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

    So max stones that can be removed = Total stones - no of connected components

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

    ur the best

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

    How do you even get those ideas ? I could have never thought of this problem in this manner.

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

      Yes, it is a difficult question. The idea is to try reducing the problem to something familiar. In this case - number of connected components in a graph.

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

      @@ShiranAfergan Thank your very much, Shiran !!

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

    That's smart!!

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

    Perfect. perfeect perfect peerrrfect

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

      Glad you liked it 😆😊

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

      @@ShiranAfergan can u plz plz increase frequency of uploading videos

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

    union find? Amortzed what? Too difficult . I m not smart enough for this. Too hard. Where can I find a simple explanation of this ?

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

      Yes, it’s a difficult question.
      If you want to read up on union-find (Disjoint-set) data structure you can find a pretty detailed explanation on Wikipedia (en.wikipedia.org/wiki/Disjoint-set_data_structure ).
      You can also check out this Union-Find playlist from William Fiset ruclips.net/p/PLDV1Zeh2NRsBI1C-mR6ZhHTyfoEJWlxvq

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

    thankuhh :) -/\-

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

    i came up with solution within 3 min of this video. good at explaining different test cases. curious to know your instagram id 😍

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

      Awesome :) thanks for watching. I don’t have an active instagram account.

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

    babe

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

    great explanation