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 Жыл бұрын
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'
@andreizegheru58424 жыл бұрын
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.
@AlgosWithMichael4 жыл бұрын
That's great to hear, thank you for the kind words!
@jacklee61064 жыл бұрын
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!
@AlgosWithMichael4 жыл бұрын
I'm so glad to hear that! More videos to come
@AlgosWithMichael4 жыл бұрын
@Sean Novick Definitely. Its important to just get the practice, that way when you see similar problems you know how to solve them.
@ichihollow102 жыл бұрын
@Sean Novick did you get the job?
@sanjeev00753 жыл бұрын
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 :)
@vineethdara67872 жыл бұрын
Yes this is true, even though it might not effect the result, direction + "0" keeps it in sync with other cases.
@rakshith35473 жыл бұрын
Probably the best explanation for this problem
@AlgosWithMichael3 жыл бұрын
Thank you!!
@larrasket2 жыл бұрын
Thanks for the great explanation. Can you please explain why it does not work without adding the "O" direction?
@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-dv2zu7 ай бұрын
Why should we store char for out-of-boundary cells and 0's? Those do not change the island's shape, do they?
@piyushkumar-wg8cv2 жыл бұрын
Very clean code. I am going to follow you from now onwards.
@AlgosWithMichael Жыл бұрын
Awesome, thank you!
@aayogkoirala80972 жыл бұрын
do you really need the U/O/R chars if you just follow the same direction every time?
@larrasket2 жыл бұрын
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 Жыл бұрын
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!
@rak5904 жыл бұрын
Keep it going michael! very clear, concise and at the same time detailed explanation.
@AlgosWithMichael4 жыл бұрын
Thank you very much, I definitely will!
@yitingg79424 жыл бұрын
Love your videos. Always very clear with full explanation. Really appreciate. Please do more!!
@AlgosWithMichael4 жыл бұрын
Thank you! Will do!
@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
@davngo4 жыл бұрын
Thanks for this, awesome explanation
@AlgosWithMichael4 жыл бұрын
You're very welcome!
@curesnow64932 жыл бұрын
Thank you so much for your explanation, I have learned a lot! :)
@ChinmayDhake3 жыл бұрын
Very clear explanation! Thanks for the video!!
@AlgosWithMichael3 жыл бұрын
Anytime!
@akyt75952 жыл бұрын
Awesome. Thanks for the great explanation.
@blackgoldendoodle4 жыл бұрын
Pretty smart logic for that Set
@AlgosWithMichael4 жыл бұрын
Haha yeah it's a little tricky. Thanks for watching!
@harshalpatil10474 жыл бұрын
i like the way you break down things and explain ... love for the videos from india brother .. keep going
@AlgosWithMichael4 жыл бұрын
Appreciate the kind words, thanks for watching!
@parsecscopeking25803 жыл бұрын
Good coding and explanation. Thanks. Btw how did you draw rectangle on screen in the end of video?
@AlgosWithMichael3 жыл бұрын
Thank you! And I use some editing software
@shamanthhirehallivenkatesh37164 жыл бұрын
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?
@AlgosWithMichael4 жыл бұрын
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
@MrAmbarish7104 жыл бұрын
Thanks for the awesome and crisp explanation man
@AlgosWithMichael4 жыл бұрын
Happy to help!
@staticFool3 жыл бұрын
thanks for the detailed explanation man.
@242deepak4 жыл бұрын
the solution which involves finding the relative coordinates of the island is more intuitive
@AlgosWithMichael4 жыл бұрын
nice
@swatisinha73824 жыл бұрын
Thanks a lot for the awesome videos. Crisp code and great explanations!
@AlgosWithMichael4 жыл бұрын
Glad you like them!
@ayonkar15344 жыл бұрын
Challenging but brialliant solution I am not sure how will I get this idea in the interview
@AlgosWithMichael4 жыл бұрын
Yea, it is very tough
@ankurrohilla46554 жыл бұрын
In just 5 minutes ..an elephant turns into an ant ..THNXX !!!!
@AlgosWithMichael4 жыл бұрын
Anytime!
@sunginjung38543 жыл бұрын
thanks for the great explanation
@AlgosWithMichael3 жыл бұрын
You are welcome!
@rathan235 Жыл бұрын
Great job
@Jeremy-yb5yo4 жыл бұрын
Great video, thank you!
@AlgosWithMichael4 жыл бұрын
My pleasure!
@aishwaryanair20714 жыл бұрын
Great explanation!
@AlgosWithMichael4 жыл бұрын
Glad it was helpful!
@aishwaryanair20714 жыл бұрын
@@AlgosWithMichael Could you please do a video explaining leetcode problem 146 LRU Cache.
@swetavkamal3 жыл бұрын
You explain well.. Why not create list such as for DFS/BFS and put up different questions in it..
@AlgosWithMichael3 жыл бұрын
I can do that, thanks for the suggestion!
@matthewsaucedo24714 жыл бұрын
Great explanation! Thanks :)
@AlgosWithMichael4 жыл бұрын
Thank you so much!
@vigneshs4494 жыл бұрын
Excellent explanation :)
@AlgosWithMichael4 жыл бұрын
Glad it helped!
@shalinsitwala4 жыл бұрын
Great help! Thanks.
@AlgosWithMichael4 жыл бұрын
Of course, glad you liked it!
@driveb65914 жыл бұрын
Great video:) Thanks Can you please upload the code on github as well?
@AlgosWithMichael4 жыл бұрын
Thank you so much! The code can be found on the discussion forums on LeetCode.
@ChinmayDhake3 жыл бұрын
If you understood the explanation, try writing the code on your own.
@dhavalbhanu4 жыл бұрын
Line 23 should return direction + "O"?
@AlgosWithMichael4 жыл бұрын
The end solution passed all the test cases on LeetCode!
@nehagour69283 жыл бұрын
Thank you
@prakharagarwal71174 жыл бұрын
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.
@AlgosWithMichael4 жыл бұрын
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.
@prakharagarwal71174 жыл бұрын
@@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.
@AlgosWithMichael4 жыл бұрын
No problem, I'm glad you figured it out. I appreciate you watching and commenting!