Next Time Using the Same Digits
Updated
Problem statement
You are given a valid 24-hour time time in zero-padded "HH:MM" format.
Find the next valid time reached strictly after time that uses exactly the same four digits with the same multiplicities. The colon is not a digit. Time advances cyclically, so the search continues into the next day when necessary.
Return the next time in zero-padded "HH:MM" format. If no different arrangement of the digits forms a valid time, return time, representing the same clock time on the next day.
Function
nextTimeUsingSameDigits(time: String) → StringExamples
Example 1
time = "09:25"return = "09:52"09:52 is the earliest later valid time made from exactly the digits 0, 9, 2, 5.
Example 2
time = "12:34"return = "12:43"Swapping the minute digits gives the earliest valid later time using the same digit multiset.
Example 3
time = "11:11"return = "11:11"No different arrangement exists, so the next matching time is 11:11 on the following day.
Constraints
time.length == 5.time[2] == ':'.timeis a valid zero-padded time from00:00through23:59.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Deduplicated Query RegistrationDatadog · ONSITE INTERVIEWDatadog interview questions
- Cheating CodemakerJane Street · OAJane Street interview questions
- File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
- Invoice / Payment ReconciliationStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
- Feature Flags with Rules, Dependencies and ExposurePerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
- Sliding Items on a Circular RingIDFC Bank · ONSITE INTERVIEWIDFC Bank interview questions
- Stateful Log Transform and SearchRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Digit-Coded Card ValidationCapital One · ONSITE INTERVIEWCapital One interview questions
- Query JSON Records with WHERE and ORDER BYGitHub · ONSITE INTERVIEW