Amazon Coding Interview Question - Number of Distinct Islands

  Рет қаралды 26,128

AlgosWithMichael

AlgosWithMichael

Күн бұрын

Пікірлер: 100
@wrishavbhattacharyya5216
@wrishavbhattacharyya5216 2 жыл бұрын
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
@rahuljha5270
@rahuljha5270 Жыл бұрын
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'
@andreizegheru5842
@andreizegheru5842 4 жыл бұрын
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!
@jacklee6106
@jacklee6106 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 жыл бұрын
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 жыл бұрын
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 :)
@vineethdara6787
@vineethdara6787 2 жыл бұрын
Yes this is true, even though it might not effect the result, direction + "0" keeps it in sync with other cases.
@rakshith3547
@rakshith3547 3 жыл бұрын
Probably the best explanation for this problem
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thank you!!
@larrasket
@larrasket 2 жыл бұрын
Thanks for the great explanation. Can you please explain why it does not work without adding the "O" direction?
@lylez00
@lylez00 Ай бұрын
I've been interviewing lately, and I'm not encountering any of these "common questions" I'm seeing on KZbin. 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!
@GoodLuck-dv2zu
@GoodLuck-dv2zu 7 ай бұрын
Why should we store char for out-of-boundary cells and 0's? Those do not change the island's shape, do they?
@piyushkumar-wg8cv
@piyushkumar-wg8cv 2 жыл бұрын
Very clean code. I am going to follow you from now onwards.
@AlgosWithMichael
@AlgosWithMichael Жыл бұрын
Awesome, thank you!
@aayogkoirala8097
@aayogkoirala8097 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.
@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!
@rak590
@rak590 4 жыл бұрын
Keep it going michael! very clear, concise and at the same time detailed explanation.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you very much, I definitely will!
@yitingg7942
@yitingg7942 4 жыл бұрын
Love your videos. Always very clear with full explanation. Really appreciate. Please do more!!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you! Will do!
@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
@davngo
@davngo 4 жыл бұрын
Thanks for this, awesome explanation
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
You're very welcome!
@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!!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Anytime!
@akyt7595
@akyt7595 2 жыл бұрын
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!
@harshalpatil1047
@harshalpatil1047 4 жыл бұрын
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!
@parsecscopeking2580
@parsecscopeking2580 3 жыл бұрын
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
@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
@MrAmbarish710
@MrAmbarish710 4 жыл бұрын
Thanks for the awesome and crisp explanation man
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Happy to help!
@staticFool
@staticFool 3 жыл бұрын
thanks for the detailed explanation man.
@242deepak
@242deepak 4 жыл бұрын
the solution which involves finding the relative coordinates of the island is more intuitive
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
nice
@swatisinha7382
@swatisinha7382 4 жыл бұрын
Thanks a lot for the awesome videos. Crisp code and great explanations!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Glad you like them!
@ayonkar1534
@ayonkar1534 4 жыл бұрын
Challenging but brialliant solution I am not sure how will I get this idea in the interview
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Yea, it is very tough
@ankurrohilla4655
@ankurrohilla4655 4 жыл бұрын
In just 5 minutes ..an elephant turns into an ant ..THNXX !!!!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Anytime!
@sunginjung3854
@sunginjung3854 3 жыл бұрын
thanks for the great explanation
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
You are welcome!
@rathan235
@rathan235 Жыл бұрын
Great job
@Jeremy-yb5yo
@Jeremy-yb5yo 4 жыл бұрын
Great video, thank you!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
My pleasure!
@aishwaryanair2071
@aishwaryanair2071 4 жыл бұрын
Great explanation!
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Glad it was helpful!
@aishwaryanair2071
@aishwaryanair2071 4 жыл бұрын
@@AlgosWithMichael Could you please do a video explaining leetcode problem 146 LRU Cache.
@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 жыл бұрын
I can do that, thanks for the suggestion!
@matthewsaucedo2471
@matthewsaucedo2471 4 жыл бұрын
Great explanation! Thanks :)
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you so much!
@vigneshs449
@vigneshs449 4 жыл бұрын
Excellent explanation :)
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Glad it helped!
@shalinsitwala
@shalinsitwala 4 жыл бұрын
Great help! Thanks.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Of course, glad you liked it!
@driveb6591
@driveb6591 4 жыл бұрын
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.
@dhavalbhanu
@dhavalbhanu 4 жыл бұрын
Line 23 should return direction + "O"?
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
The end solution passed all the test cases on LeetCode!
@nehagour6928
@nehagour6928 3 жыл бұрын
Thank you
@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 жыл бұрын
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 жыл бұрын
@@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 жыл бұрын
No problem, I'm glad you figured it out. I appreciate you watching and commenting!
@soulboy2223
@soulboy2223 3 жыл бұрын
nice solution!
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thanks!
@manojrajasekar6035
@manojrajasekar6035 4 жыл бұрын
Awesome !
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you kind sir!
@kamalpyl
@kamalpyl 4 жыл бұрын
Thanks
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
No problem, glad you liked it!
@MayaBello
@MayaBello 4 жыл бұрын
👏🏿👏🏿👏🏿👏🏿
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
:D
@92AkshaySharma
@92AkshaySharma 4 жыл бұрын
thanks
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
No prob!
@yueyichen793
@yueyichen793 4 жыл бұрын
MLE
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thanks for watching and commenting!
Google Coding Interview Question - Number of Closed Islands (LeetCode)
21:03
Amazon Coding Interview Question - First Missing Positive (LeetCode)
20:47
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,6 МЛН
Technical Interview Question - Max Area of Island [LeetCode]
26:18
AlgosWithMichael
Рет қаралды 9 М.
Word Ladder | Breadth First Search (LeetCode)
15:08
AlgosWithMichael
Рет қаралды 14 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Amazon Coding Interview Question - Clone Graph (LeetCode)
13:56
AlgosWithMichael
Рет қаралды 33 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 438 М.
Count Number of Teams - Leetcode 1395 - Python
17:29
NeetCodeIO
Рет қаралды 13 М.
Technical Interview Question: Number of Islands [LeetCode]
17:48
AlgosWithMichael
Рет қаралды 32 М.
Coding Unbreakable Encryption in C | One-Time Pad
17:42
HirschDaniel
Рет қаралды 4,4 М.
Google Coding Question - Making a Large Island (Hard)
25:11
AlgosWithMichael
Рет қаралды 16 М.