FastPrepNext Time Using the Same Digits
Problems/Next Time Using the Same Digits

Next Time Using the Same Digits

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand Software Engineer intern report describes a combinatorics task asking for the next time that uses exactly the same digits, and cites 09:25 to 20:59. That reported example is inconsistent, because 09:52 is an earlier valid time with the same digits. Our rebuild follows the stated next-time rule. It uses a zero-padded 24-hour clock, exact digit counts, and a search that wraps around, so it expects 09:52. Our version is about 80% the same as the reported question.

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) → String

Examples

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] == ':'.
  • time is a valid zero-padded time from 00:00 through 23: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

Interview reports that mention this question

  • Google SWE Intern Onsite Questions: 16 Experiences (Part 2 of 3)

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String nextTimeUsingSameDigits(String time) {
        // Write your code here.
    }
}
Checking account…