Practice
Date Validator With Leap Years
HARDValidation10 marks
Read a day, month, and year. Output Valid if the date exists, otherwise output Invalid.
February has 29 days in a leap year and 28 days otherwise. A leap year is divisible by 400, or divisible by 4 but not divisible by 100.
Input: Day, month, then year. Output: Valid or Invalid.
Example:
Input: 29
2
2024
Output: Valid
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Leap day in a leap year
Inputs: 29, 2, 2024
Expected: Valid
Test 2: Leap day in a normal year
Inputs: 29, 2, 2023
Expected: Invalid
Test 3: April has 30 days
Inputs: 31, 4, 2025
Expected: Invalid