Bucket Sort Interview Question - Min Time Difference (Amazon)

  Рет қаралды 4,880

AlgosWithMichael

AlgosWithMichael

Күн бұрын

Пікірлер
@vikashkatiyar1225
@vikashkatiyar1225 2 ай бұрын
Thank you, Michael! I really appreciate how you break down complex concepts into simple, easy-to-understand terms. Your explanations are always clear and concise. Keep up the fantastic work, and I hope your audience continues to grow!
@joshuaalonge1351
@joshuaalonge1351 3 жыл бұрын
This is the best explanation that I have seen for this question. Good one
@satang500
@satang500 2 жыл бұрын
Thanks for your explanation with the drawing and image which really helps. I watched other videos, but didn't fully understand until I watch yours. :)
@shrimpo6416
@shrimpo6416 2 жыл бұрын
Great explanation!!!! Excellent!!!
@mikasaackerman2694
@mikasaackerman2694 4 жыл бұрын
Very clear explanation! I've watched some of your other videos too. You definitely deserve more subscribers.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
I appreciate that!
@ninehoursful
@ninehoursful 4 жыл бұрын
How can someone come up with such a solution in an interview situation if they haven't seen this question before? I tried to solve it myself for 12 hours but I couldn't solve it! This is just scaring me
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Once you see how a problem is solved, you can solve other problems that are similar. It is just about having the general idea, so don't feel bad if you can't think of it the first time you see this type of problem. Keep practicing and it will get easier
@ninehoursful
@ninehoursful 4 жыл бұрын
@@AlgosWithMichael Thanks for the kind words. My problem is even if I see/have done the question, I forget the process/tricks used to solve the questions. How do you overcome that?
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Yea, it can be tough. What I think you should do so it is remembered easier is study one topic for many days in succession. So for example, if you feel you are not good with sorting questions, just practice sorting questions / topics for a week straight instead of jumping from trees to graphs to anything else etc. It will stick much better that way
@andrejoljaca3577
@andrejoljaca3577 3 жыл бұрын
So good at explaining! Incredible
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Thanks! 😃
@SheikhSadiruddin1
@SheikhSadiruddin1 4 жыл бұрын
Awesome explanation Michael! I love the way you explain complex things in a simple manner. Keep up the good work. I hope you you get more subscribers.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thank you very much!
@chaoschao9432
@chaoschao9432 4 жыл бұрын
deserve more subscribers. good job.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
I appreciate that, thank you!
@symbol767
@symbol767 2 жыл бұрын
Great solution, thank you
@AlgosWithMichael
@AlgosWithMichael 2 жыл бұрын
You bet
@sarvesh97
@sarvesh97 4 жыл бұрын
Amazing explanation! 🔥
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Thanks so much!
@kishorshinde5567
@kishorshinde5567 4 жыл бұрын
Thanks for sharing this problem with solution. After you video, I thought instead of looping 1440 times, we can loop 2*input array times and came up with below solution. public static void main(String[] args) { // TODO Auto-generated method stub String []arr = new String[] {"01:00","03:00","23:30"}; int[] times = new int[arr.length]; int k=0; for(String s : arr) { String hour_Min[] = s.split(":"); int h = Integer.parseInt(hour_Min[0]); int m = Integer.parseInt(hour_Min[1]); times[k++] = h *60 + m; } System.out.println(); display(times); int min = Integer.MAX_VALUE; for(int i=0;i
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Ah I like that approach 👍
@heisenberg1844
@heisenberg1844 4 жыл бұрын
Nice. Can you please elaborate the wrap around part(1440-cur-first) a little more? Thanks.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
Sure. 1440 is the total amount of minutes in a day. Thus, we subtract cur which accounts for the "ending" of the first day, then subtract first which accounts for the "start" of the second day. Hope that makes sense for you!
@ShashwataSaha
@ShashwataSaha 3 жыл бұрын
This gives better time complexity. from sys import maxsize class Solution: def findMinDifference(self, timePoints: List[str]) -> int: for x in range(len(timePoints)): hr,mi=map(int,timePoints[x].split(":")) hr*=60 timePoints[x]=hr+mi timePoints.sort() mini=maxsize for x in range(len(timePoints)-1): temp=abs(timePoints[x]-timePoints[x+1]) mini=min(mini,temp) mini=min(mini,(60*24-timePoints[-1])+timePoints[0]) return mini
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
nice
@Kacperak23
@Kacperak23 4 жыл бұрын
Isn't that more like the counting sort? You have 1-1 relationship in your buckets, but usually buckets have many items inside of them which you sort normally.
@AlgosWithMichael
@AlgosWithMichael 4 жыл бұрын
it is similar to counting sort yea
@rohanangajala548
@rohanangajala548 3 жыл бұрын
What was the point of creating buckets and have all the false values? Isn't this essentially the same as just iterating through the array and keeping track of all the different pointers?
@AlgosWithMichael
@AlgosWithMichael 3 жыл бұрын
Since the size of our buckets is always the same, it is technically constant space :)
@michaelroatis6874
@michaelroatis6874 2 жыл бұрын
About the time complexity, can we say constant time since its bound by the number 1440? bucket.length in the second loop is always 1440, and if we have more than 1440 timePoints we'll always return 0 in the first for loop
Google Coding Question - Long Pressed Name (Two Pointers Approach)
14:23
AlgosWithMichael
Рет қаралды 4,5 М.
Google Coding Question - Making a Large Island (Hard)
25:11
AlgosWithMichael
Рет қаралды 16 М.
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 12 МЛН
When u fight over the armrest
00:41
Adam W
Рет қаралды 31 МЛН
Solving Amazon's 2020 Most Asked Interview Question
9:57
AlgosWithMichael
Рет қаралды 18 М.
Amazon Coding Interview Question - First Missing Positive (LeetCode)
20:47
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 94 М.
Minimum Time Difference - Leetcode 539 - Python
21:43
NeetCodeIO
Рет қаралды 8 М.
Amazon Coding Interview Question - Min Stack (LeetCode)
8:34
AlgosWithMichael
Рет қаралды 7 М.
FAANG Coding Interview Question - Container With Most Water (LeetCode)
13:30
Solving Amazon's 2024 Most Asked Coding Question
18:09
AlgosWithMichael
Рет қаралды 4,5 М.
Quicksort: Partitioning an array
4:48
KC Ang
Рет қаралды 591 М.