My idea is different, hope this helps someone. My solution does use extra space. it uses a min heap to sort it in nlogn time after fixing the edge case. The way to beat the issue of the time going past midnight is to just add 1440 minutes or 24 hours to each timePoints as a new point. If you think about it, 00:00 is no different from 24:00, so we're just adding the extra day to fix our edge case issue. For example, if the test case is [00:00, 23:59], the list is now [00:00,23:59, 24:00, 47:59] in a min heap. Then you can easily just convert it to all to minutes. Then in a simple while loop, pop from head, let's call it a, and do an lowest = min(lowest, abs(a - minHeap[0])) and watch out for the edge case of when minHeap is length of 1 as it doesn't have anything to compare if it's the last item in the heap.
@yourick932 ай бұрын
There is one missing point of using the second approach. In the line 23 we have to iterate till the `last_m` (max possible minute from the line 15) instead of `len(exists)`. It will improve efficiency for some test cases.
@NeetCodeIO2 ай бұрын
Oh good point 💡
@MikPosp2 ай бұрын
Thanks for your video! Here is a solution in one line: def findMinDifference(self, a): return min(map(sub,(q:=sorted(int(s[:2])*60+int(s[3:]) for s in a))[1:]+[q[0]+1440],q))
@provarence7361Ай бұрын
yep good luck using this in an interview
@adilansari-hq9ge2 ай бұрын
As always Awesome solution. Last year had interview with DocuSign and I could not clear that round , all because i used built in sorting , but they were expecting counting Sort.
@ACium.2 ай бұрын
Oh counting sort!
@Ryan-g7h2 ай бұрын
note that the min part only works when the time is sorted, ty for the great solution
@2EOGIY2 ай бұрын
That solution is missing the fact that there will be no bigger distance than 12h, so half of 1440
@NeetCodeIO2 ай бұрын
good point! technically 1440 is still a more precise upperbound than float("inf"), but you're write, 720 should be sufficient as well
@Axel.Blazer2 ай бұрын
@@NeetCodeIO print(f"{write}")
@saarthak092 ай бұрын
My JS Solution beats 97% Thank You NeetCode :)
@albin_joby2 ай бұрын
if timePoints.count(min(timePoints)) > 1: return 0 for i in range(len(timePoints)): h,m = map(int,timePoints[i].split(":")) timePoints[i] = m+(h*60) timePoints.sort() res = 1440 - timePoints[-1] + timePoints[0] for i in range(1, len(timePoints)): diff = timePoints[i]-timePoints[i-1] res = min(res, diff) return res
@parica1172 ай бұрын
thank you bro
@leo881010able2 ай бұрын
The part you initialize the res was mind blowing, gotta watch daily problem everyday no matter whether I can solve the question✨
@provarence7361Ай бұрын
So for the second part, you are not computing the two diffs for each set of time points correct? You said you would in the explanation but I dont think this approach does unless I'm wrong
@cineaddict16332 ай бұрын
Neetcode make a video on sieve of eratosthenes please
@greedyfishbones2 ай бұрын
Avg neetcode W
@Corgislife12152 ай бұрын
Like if you love neetcode!
@pravyn3502 ай бұрын
Off course 😂
@teress13162 ай бұрын
downvote if you don't like people begging for likes.