FastPrepMinimum Difference Between Two Clock Times

Minimum Difference Between Two Clock Times

Micron Technology logoMicron Technology● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Each input is a lowercase 12-hour clock time in the form h:mmam or h:mmpm. Return the smaller number of minutes separating the two readings on a 24-hour clock.

Function

minimumTimeDifference(first: String, second: String) → int

Examples

Example 1

first = "11:30pm"second = "3:00pm"return = 510

The same-day separation is eight hours and thirty minutes.

Example 2

first = "11:50pm"second = "12:10am"return = 20

The shorter separation crosses midnight.

Constraints

  • Both inputs are valid normalized 12-hour times.

Source note: Author-written prompt excerpt retained for source fidelity.

See Micron Technology hiring insights
public int minimumTimeDifference(String first, String second) {
    // Write your code here.
}
first"11:30pm"
second"3:00pm"
expected510
Checking account…