Amazon Coding Interview Question - Number of Distinct Islands

แชร์
ฝัง
  • เผยแพร่เมื่อ 11 ธ.ค. 2024

ความคิดเห็น • 100

  • @andreizegheru5842
    @andreizegheru5842 4 ปีที่แล้ว +5

    Very good video. There are a lot of channels that have the same content (leetcode problems), and the difference between them is made by how well the solution is explained. Yours is one of the best I've seen so far, so keep it up.

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      That's great to hear, thank you for the kind words!

  • @wrishavbhattacharyya5216
    @wrishavbhattacharyya5216 2 ปีที่แล้ว +3

    There's also one another way , by storing the visiting order of the x , y coordinate of the dfs traversal ,
    Let px , py be your starting position of the island
    Whichever position of that island you visit , just insert that into the vector { x - px , y - py } == > storing the relative position
    insert this vector into the set

  • @jacklee6106
    @jacklee6106 4 ปีที่แล้ว +4

    Thanks for the videos. I remembered watching your *Number of islands * video and now I got a job at Amazon as Software engineer. Keep it up!

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว +1

      I'm so glad to hear that! More videos to come

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      @Sean Novick Definitely. Its important to just get the practice, that way when you see similar problems you know how to solve them.

    • @ichihollow10
      @ichihollow10 2 ปีที่แล้ว

      @Sean Novick did you get the job?

  • @sanjeev0075
    @sanjeev0075 3 ปีที่แล้ว +6

    Hi Michael,
    Nice explanation....just wanted to point out the small difference in implementation and explanation...In base case I guess we should return direction+"0" compared to "0". Even though the code will still work as the representation of water is "0" compared to direction+"0". Thought to point it out for other users. Thanks again for such a beautiful explanation :)

    • @vineethdara
      @vineethdara 2 ปีที่แล้ว

      Yes this is true, even though it might not effect the result, direction + "0" keeps it in sync with other cases.

  • @rahuljha5270
    @rahuljha5270 ปีที่แล้ว +2

    can i avoid storing out of bounds character 'O' in the string. Why the test case fails in that case. I just want to store 'R' 'L' 'U' and 'D'

  • @rakshith3547
    @rakshith3547 3 ปีที่แล้ว

    Probably the best explanation for this problem

  • @piyushkumar-wg8cv
    @piyushkumar-wg8cv 2 ปีที่แล้ว

    Very clean code. I am going to follow you from now onwards.

  • @yitingg7942
    @yitingg7942 4 ปีที่แล้ว

    Love your videos. Always very clear with full explanation. Really appreciate. Please do more!!

  • @rak590
    @rak590 4 ปีที่แล้ว

    Keep it going michael! very clear, concise and at the same time detailed explanation.

  • @larrasket
    @larrasket 2 ปีที่แล้ว +1

    Thanks for the great explanation. Can you please explain why it does not work without adding the "O" direction?

  • @harshalpatil1047
    @harshalpatil1047 4 ปีที่แล้ว +1

    i like the way you break down things and explain ... love for the videos from india brother .. keep going

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Appreciate the kind words, thanks for watching!

  • @davngo
    @davngo 4 ปีที่แล้ว +2

    Thanks for this, awesome explanation

  • @MrAmbarish710
    @MrAmbarish710 4 ปีที่แล้ว

    Thanks for the awesome and crisp explanation man

  • @curesnow6493
    @curesnow6493 2 ปีที่แล้ว

    Thank you so much for your explanation, I have learned a lot! :)

  • @ChinmayDhake
    @ChinmayDhake 3 ปีที่แล้ว

    Very clear explanation! Thanks for the video!!

  • @akyt7595
    @akyt7595 3 ปีที่แล้ว

    Awesome. Thanks for the great explanation.

  • @blackgoldendoodle
    @blackgoldendoodle 4 ปีที่แล้ว

    Pretty smart logic for that Set

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Haha yeah it's a little tricky. Thanks for watching!

  • @aayogkoirala8097
    @aayogkoirala8097 2 ปีที่แล้ว +2

    do you really need the U/O/R chars if you just follow the same direction every time?

    • @larrasket
      @larrasket 2 ปีที่แล้ว

      I've been thinking of the same question. I implemented the same solution without tracking of out/water directions but it didn't seem to be work.

  • @lylez00
    @lylez00 หลายเดือนก่อน

    I've been interviewing lately, and I'm not encountering any of these "common questions" I'm seeing on TH-cam. They're all different, and they're all hard. My question today - just the question and the examples of solutions was 63 lines, and I had about 20 minutes to solve it. I am so sick of the IT industry!

  • @staticFool
    @staticFool 3 ปีที่แล้ว

    thanks for the detailed explanation man.

  • @rathan235
    @rathan235 ปีที่แล้ว

    Great job

  • @GoodLuck-dv2zu
    @GoodLuck-dv2zu 8 หลายเดือนก่อน

    Why should we store char for out-of-boundary cells and 0's? Those do not change the island's shape, do they?

  • @sunginjung3854
    @sunginjung3854 3 ปีที่แล้ว

    thanks for the great explanation

  • @manjus3
    @manjus3 ปีที่แล้ว

    Hi Michael, great explanation! Regarding space complexity, wouldn't you have to consider the space for the set? And if so, how would you express that? Thanks!

  • @swatisinha7382
    @swatisinha7382 4 ปีที่แล้ว

    Thanks a lot for the awesome videos. Crisp code and great explanations!

  • @aishwaryanair2071
    @aishwaryanair2071 4 ปีที่แล้ว

    Great explanation!

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว +1

      Glad it was helpful!

    • @aishwaryanair2071
      @aishwaryanair2071 4 ปีที่แล้ว

      @@AlgosWithMichael Could you please do a video explaining leetcode problem 146
      LRU Cache.

  • @noopuragarwal7893
    @noopuragarwal7893 ปีที่แล้ว

    Thanx , Nice sol! .. Could you also help with Number of Distinct Islands II - LC 711 , i tried sorting the string and then stroing but looks like its not same method .. could you please help

  • @parsecscopeking2580
    @parsecscopeking2580 3 ปีที่แล้ว +1

    Good coding and explanation. Thanks. Btw how did you draw rectangle on screen in the end of video?

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว

      Thank you! And I use some editing software

  • @Jeremy-yb5yo
    @Jeremy-yb5yo 4 ปีที่แล้ว

    Great video, thank you!

  • @shalinsitwala
    @shalinsitwala 4 ปีที่แล้ว

    Great help! Thanks.

  • @vigneshs449
    @vigneshs449 4 ปีที่แล้ว

    Excellent explanation :)

  • @nehagour6928
    @nehagour6928 3 ปีที่แล้ว

    Thank you

  • @ayonkar1534
    @ayonkar1534 4 ปีที่แล้ว +1

    Challenging but brialliant solution I am not sure how will I get this idea in the interview

  • @242deepak
    @242deepak 4 ปีที่แล้ว

    the solution which involves finding the relative coordinates of the island is more intuitive

  • @prakharagarwal7117
    @prakharagarwal7117 4 ปีที่แล้ว

    I think time complexity will be m*n*m*n. For the worst case when we have all ones. DFS will visit each element, and make all 1's to 0's but that would not break the for loop, and it will check for all the zero values.

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว +1

      I see what your saying, but I still think it would be O(M*N) because even in the worst case when we have all ones and it has to perform DFS over the entire array, then loop over all the zeros, that means it will touch each position twice. Touching each element twice is not the same thing as O(M^2*N^2), it is O(2*M*N), then drop the constant.

    • @prakharagarwal7117
      @prakharagarwal7117 4 ปีที่แล้ว +1

      @@AlgosWithMichael Well you were very quick to reply. I was just about to delete the comment. I figured it out, I just took the worst case and did on paper, and yes it will be m*n. Sorry, I don't know what was I imagining while running the algo in my mind.

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว +2

      No problem, I'm glad you figured it out. I appreciate you watching and commenting!

  • @soulboy2223
    @soulboy2223 4 ปีที่แล้ว

    nice solution!

  • @ankurrohilla4655
    @ankurrohilla4655 4 ปีที่แล้ว

    In just 5 minutes ..an elephant turns into an ant ..THNXX !!!!

  • @shamanthhirehallivenkatesh3716
    @shamanthhirehallivenkatesh3716 4 ปีที่แล้ว

    The string concatenation is a linear time operation that we do at every recursion call right? Why is it not considered for the time complexity analysis?

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      I actually didn't think of that. Since the strings are immutable in Java it would make sense that is a linear time operation, but not sure haha

  • @matthewsaucedo2471
    @matthewsaucedo2471 4 ปีที่แล้ว

    Great explanation! Thanks :)

  • @dhavalbhanu
    @dhavalbhanu 4 ปีที่แล้ว

    Line 23 should return direction + "O"?

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      The end solution passed all the test cases on LeetCode!

  • @swetavkamal
    @swetavkamal 3 ปีที่แล้ว

    You explain well.. Why not create list such as for DFS/BFS and put up different questions in it..

    • @AlgosWithMichael
      @AlgosWithMichael  3 ปีที่แล้ว +1

      I can do that, thanks for the suggestion!

  • @manojrajasekar6035
    @manojrajasekar6035 4 ปีที่แล้ว

    Awesome !

  • @driveb6591
    @driveb6591 4 ปีที่แล้ว +1

    Great video:) Thanks
    Can you please upload the code on github as well?

    • @AlgosWithMichael
      @AlgosWithMichael  4 ปีที่แล้ว

      Thank you so much! The code can be found on the discussion forums on LeetCode.

    • @ChinmayDhake
      @ChinmayDhake 3 ปีที่แล้ว

      If you understood the explanation, try writing the code on your own.

  • @kamalpyl
    @kamalpyl 4 ปีที่แล้ว

    Thanks

  • @92AkshaySharma
    @92AkshaySharma 4 ปีที่แล้ว

    thanks

  • @MayaBello
    @MayaBello 4 ปีที่แล้ว

    👏🏿👏🏿👏🏿👏🏿

  • @yueyichen793
    @yueyichen793 4 ปีที่แล้ว

    MLE