Bucket Sort Interview Question - Min Time Difference (Amazon)

แชร์
ฝัง
  • เผยแพร่เมื่อ 18 ก.ย. 2024

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

  • @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!

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

    Very clear explanation! I've watched some of your other videos too. You definitely deserve more subscribers.

  • @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. :)

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

    Great solution, thank you

  • @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.

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

    deserve more subscribers. good job.

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

    Great explanation!!!! Excellent!!!

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

    So good at explaining! Incredible

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

    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 ปีที่แล้ว +1

      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

  • @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

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

    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

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

    Amazing explanation! 🔥

  • @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 :)

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

    Nice. Can you please elaborate the wrap around part(1440-cur-first) a little more? Thanks.

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

      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!

  • @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.

  • @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