Skip to content

Instantly share code, notes, and snippets.

@Fredpwol
Last active May 27, 2021 17:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fredpwol/35965f6e036e45a5356ade46036ee345 to your computer and use it in GitHub Desktop.
Save Fredpwol/35965f6e036e45a5356ade46036ee345 to your computer and use it in GitHub Desktop.
Find Minimum Time Difference
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
@meekg33k
Copy link

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 and O(N log N) time complexity?

I'd love to hear you thoughts.

@Fredpwol
Copy link
Author

Hello, @meekg33k Thanks again for the feedback. I've updated my code to meet the specifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment