![]() |
VOOZH | about |
Given a date, check if it is valid or not. It may be assumed that the given date is in range from 01/01/1800 to 31/12/9999.
Examples :
Input : d = 10, m = 12, y = 2000 Output : Yes The given date 10/12/2000 is valid Input : d = 30, m = 2, y = 2000 Output : No The given date 30/2/2000 is invalid. The February month cannot have 30 as day.
The idea is simple. We need to handle following things.
1) y, m and d are in allowed range.
2) Days in February are in allowed range and leap year is handled.
3) Days in 30 day months are handled.
Below is the implementation to check if a given year is valid or not.
Output :
Yes No
Time Complexity: O(1)
Auxiliary Space: O(1), since no extra space has been taken.