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!
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
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
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
@@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?
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
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?
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!
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.
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
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
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!
This is the best explanation that I have seen for this question. Good one
Very clear explanation! I've watched some of your other videos too. You definitely deserve more subscribers.
I appreciate that!
Great explanation!!!! Excellent!!!
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.
Thank you very much!
Great solution, thank you
You bet
So good at explaining! Incredible
Thanks! 😃
deserve more subscribers. good job.
I appreciate that, thank you!
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
Ah I like that approach 👍
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
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
@@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?
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
Amazing explanation! 🔥
Thanks so much!
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?
Since the size of our buckets is always the same, it is technically constant space :)
Nice. Can you please elaborate the wrap around part(1440-cur-first) a little more? Thanks.
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!
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.
it is similar to counting sort yea
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
nice
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