Can Three Numbers Form a Valid Date?
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.