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.
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 C++/Python implementation to check if a given year is valid or not.
This article is contributed by RAHUL NITKKR. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check whether right angled triangle is valid or not for large sides
- Check whether triangle is valid or not if sides are given
- Check if the given chessboard is valid or not
- Check if the given Prufer sequence is valid or not
- Check whether the triangle is valid or not if angles are given
- Check whether Quadrilateral is valid or not if angles are given
- Check whether triangle is valid or not if three points are given
- Date after adding given number of days to the given date
- Check if a + b = c is valid after removing all zeroes from a, b and c
- Check if the number is valid when flipped upside down
- Check if the given Binary Expressions are valid
- Check if the given permutation is a valid BFS of a given Tree
- Program to generate all possible valid IP addresses from given string | Set 2
- Find the number of valid parentheses expressions of given length
- Minimum number of Parentheses to be added to make it valid
- Count valid pairs in the array satisfying given conditions
- Remove elements to make array satisfy arr[ i+1] < arr[i] for each valid i
- Arrange numbers to form a valid sequence
- Number of valid indices in the permutation of first N natural numbers
- Total number Of valid Home delivery arrangements
Improved By : nitin mittal