Last active
May 27, 2021 17:43
-
-
Save Fredpwol/35965f6e036e45a5356ade46036ee345 to your computer and use it in GitHub Desktop.
Find Minimum Time Difference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_minutes(time_string): | |
hour, min = time_string.split(":") | |
hour, min = int(hour), int(min) | |
hour *= 60 | |
return hour + min | |
def findMinimumTimDiff(times): | |
if times == None or len(times) == 0: return 0 | |
for i in range(len(times)): | |
times[i] = convert_minutes(times[i]) | |
min = float("inf") | |
times.sort() | |
for i in range(len(times)-1): | |
diff = abs(times[i] - times[i+1]) | |
if diff < min: | |
min = diff | |
return min | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @Fredpwol, thank you for participating in Week 7 of #AlgorithmFridays.
Your solution to help Esther get better at time management works for the most part. I like your use of DP but as you rightly mentioned, the trade-off with that is you had to use
O(N^2)
memory.Do you think there's a more optimal way you could have solved this problem? By optimal I mean,
O(1)
space andO(N log N)
time complexity?I'd love to hear you thoughts.