## fizzbuzzer.com

### Looking for good programming challenges?

Use the search below to find our solutions for selected questions!

# Get minimum time difference challenge

Sharing is caring!

Problem statement
Given an array of times in `HH:MM` format, find the minimum difference in minutes. The time is circular in nature. For example `23:52` and `00:08` have a difference of `16`. Also `00:00` should be handled the same as `24:00`.

Solution
The first key is to convert the `string` representation of each time into an `int` representing minutes:

Next, we iterate over the times and subtract each time from the following one checking for a new minimum each time:

The last step is to complete the circle and make the first time the follower of the last time in the array by adding $1440\ (24\ hours)$ and subtracting the last time from it:

Full code