Minimum Difference Between Two Clock Times
Updated
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) → intExamples
Example 1
first = "11:30pm"second = "3:00pm"return = 510The same-day separation is eight hours and thirty minutes.
Example 2
first = "11:50pm"second = "12:10am"return = 20The shorter separation crosses midnight.
Constraints
- Both inputs are valid normalized 12-hour times.
Source note: Author-written prompt excerpt retained for source fidelity.
Similar questions at other companies
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Stack Formula InterpreterTypeSafe AI · PHONE SCREEN
- Roman to IntegerKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Decimal Digits in OrderZoomInfo · PHONE SCREEN
- Add Two Integers Given as StringsJane Street · PHONE SCREENJane Street interview questions
- Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
- Integer to String Without Built-insHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Excel Sheet Column TitleUiPath · PHONE SCREEN