You are given an year Y, find the next identical calendar year to Y.
Input : 2017 Output : 2023 Input : 2018 Output : 2029
An year x is identical to a given previous year y if following two conditions are satisfied.
- x starts with same day as y.
- If y is leap year, then x is also. If y is not leap year, then x is also not.
The idea is to check all years one by one (starting from next year). We keep track of number of days moved ahead. If total moved days is 7, then current year begins with same day. We also check if leap-ness of current year is same as y. If both conditions are satisfied, we return current year.
This article is contributed by Shivam Pradhan (anuj_charm). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.
- Calendar Functions in Python | Set 1( calendar(), month(), isleap()...)
- Print calendar for a given year in C++
- Program to check if a given year is leap year
- Count how many times the given digital clock shows identical digits
- Minimum area of square holding two identical rectangles
- Calendar Functions in Python | Set 2(monthrange(), prcal(), weekday()...)
- Calendar.before() method in Java
- Calendar.get() Method in Java
- java.util.Calendar.after() method
- Calendar.equals() method in Java
- Print day of week using Gregorian Calendar in java
- Program to find century for a year
- Find the next greater element in a Circular Array
- Python program to calculate age in year
- How to calculate the Easter date for a given year using Gauss' Algorithm
- How to get Day, Month and Year from Date in Java
- Maximum previous and next element product
- Maximum element in an array such that its previous and next element product is maximum
- Find day of the week for a given date
- Find the maximum distance covered using n bikes