![]() |
VOOZH | about |
Given two years. Write a program to count the number of days between the two years.
Examples:
Input: startYear = 1990, endYear = 2001
Output: 4383
Explanation: Years 1992, 1996 and 2000 are leap year and all 9 others are non-leap years. So, total number of days are: 366 * 3 + 365 * 9 = 4383Input: startYear = 1890, endYear = 1998
Output: 39811
Approach: To solve the problem, follow the below idea:
The Approach is to iterate from the starting year to the ending year, and for each of them check if the given year is a leap year or not, as leap year has 366 days while non leap year has 365 days.
Step-by-step approach:
Below is the implementation of the above approach:
Number of days between 1890 and 1998 is: 39811 days.
Time Complexity: O(N), where N is the number of years between start and end year.
Auxiliary space: O(1)