Can Three Numbers Form a Valid Date?
Updated
Problem statement
Given three positive integers, decide whether some permutation can represent a valid Gregorian date [year,month,day].
The year must be in [1,9999]. Apply ordinary Gregorian leap-year rules: divisible by 400, or divisible by 4 but not 100. Each input number is used exactly once.
Function
canFormValidDate(values: int[]) → booleanExamples
Example 1
values = [2024,2,29]return = true2024 is a leap year, so February 29 is valid.
Example 2
values = [31,4,2024]return = falseNo permutation forms a valid date because April has only 30 days and the other placements fail month/year bounds.
Example 3
values = [12,25,2025]return = trueThe permutation [2025,12,25] is valid.
Constraints
values.length = 3.1 <= values[i] <= 9999.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
- Exponential Backoff DelaysWonderful · PHONE SCREEN
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN
- Latency Bucket CounterDatadog · OA · PHONE SCREENDatadog interview questions
- Mini-Batch Data LoaderOpenAI · PHONE SCREENOpenAI interview questions
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
- Deterministic K-Means AssignmentsLyft · PHONE SCREENLyft interview questions
- Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions