FunctionRacerProblemsRace

Valid Calendar Date

EasyStringsPython, JavaScript, TypeScript, Java, C++

Return True if s is a valid calendar date written as YYYY-MM-DD, otherwise False. All of these must hold:

Anything else, such as letters, extra characters or a missing zero as in 2024-5-01, makes the date invalid.

Example 1

s "2024-02-29"
returns true

2024 is divisible by 4 and not by 100, so February has 29 days.

Example 2

s "2023-02-29"
returns false

2023 is not a leap year, so February 29 does not exist.

Example 3

s "2024-5-01"
returns false

The month must be written with two digits.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems