Next Date With All Different Digits
Updated
Problem statement
Write a date as eight digits: the day with two digits, the month with two digits and the year with four digits. For example, 10 May 2020 is written 10052020, and 3 January 1999 is written 03011999.
You are given a date as day, month and year in the Gregorian calendar. Find the first date strictly after it whose eight digits are all different.
Return that date as [day, month, year].
Leap years follow the usual rule: a year is a leap year if it is divisible by 4, except years divisible by 100 that are not divisible by 400.
Function
nextDistinctDigitDate(day: int, month: int, year: int) → int[]Examples
Example 1
day = 10month = 5year = 2020return = [17,6,2345]Every month from 01 to 12 uses a 0 or a 1, and every day starts with 0, 1, 2 or 3. Checking the cases, a day and a month together always use at least two digits from 0, 1, 2, 3, and a year in the 2000s already uses the 2. That rules out every year that starts with 20, 21 or 22. The first year from 2300 on with four different digits that leaves both 0 and 1 free is 2345. The day and month must then take 0, 1 and two of 6, 7, 8, 9. The earliest such date is day 17 of month 06, written 17062345.
Example 2
day = 23month = 4year = 1965return = [27,4,1965]The next days are 24041965, 25041965 and 26041965, which repeat 4, 5 and 6. The day after that is 27041965, and its eight digits are all different.
Example 3
day = 31month = 12year = 1956return = [24,3,1957]The year 1957 uses 1, 9, 5 and 7. January (01) repeats the 1. In February (02) the month uses 0 and 2, so the day would have to start with 3, and February has no day 30 or 31. In March (03) the day must start with 2, and the smallest free second digit is 4. So the answer is 24031957.
Constraints
1900 <= year <= 90001 <= month <= 121 <= day <= 31day,monthandyearform a real date.
More Jane Street Phone Screen questions
- Maximum-Scoring Consecutive Tree LevelsPHONE SCREEN · Seen Nov 2026
- Tree Selection and VisibilityPHONE SCREEN · Seen Nov 2026
- Load/Store Arithmetic InterpreterPHONE SCREEN · Seen Oct 2026
- Instrument Stack Language JumpsPHONE SCREEN · Seen Oct 2026
- Run a Stack Language InterpreterPHONE SCREEN · Seen Oct 2026
- Positive-Integer Expression EvaluationPHONE SCREEN · Seen Oct 2026
- Add Two Integers Given as StringsPHONE SCREEN · Seen Sep 2026
- Angle Between Clock HandsPHONE SCREEN · Seen Jul 2026
- Route Length From Two CyclistsPHONE SCREEN · Seen Jul 2026
- Sort TradesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
- Exponential Backoff DelaysWonderful · PHONE SCREEN
- Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
- Smaller Clock Hand AngleAmazon · PHONE SCREEN
- Count Months Starting on SundayWalmart · PHONE SCREENWalmart interview questions