Write a program to find the number of months in the given interval where Sunday after the second Friday is also the second last (penultimate) Sunday of the month.
for example:
In Feb 2020, the second Friday is on the 14th of Feb.
Sunday after it is on the 16th Feb.
and this Sunday is also the second last Sunday of the month.
input: starting month and year and ending month and year.
output: number of such months.
constraints: 1<=year<=10e8.
I just got a clue that every feb which has its first friday on 7th will be this type of month. But there's something more which I'm not able to figure out.
There are only 7 unique calendars for non-leap years, which occur slightly more 75% of the time, and 7 unique leap year calendars which occur slightly less than 25% of the time.
I thought you already had figured out one such example.
You seem to know that it is at least possible in some circumstances that a month with 29 days can satisfy your criteria.
The next step would be to see if you can ever have a month of 30 days. If the answer is no, then you have an easy task of figuring out which of the 14 possible Februaries work.
Then it's just a matter of figuring out which years the magic Februaries fall in.
Even if there are some 30 day months which work, I'm guessing it's a sparse result.
Your satisfaction criteria fix the gap between the 2nd Friday and the penultimate Sunday at 2 days. This means that no month with 30 or more days can satisfy your criteria, since the gap between the latest possible Friday and earliest possible Sunday is >2 for those months.
Therefore, you only have to deal with February. There are two kinds of February: a 28-day variety and a 29-day variety. You can determine which kind of February you have by using the year to determine whether or not it is a leap year.
The 29-day variety has only one satisfying arrangement: taking the latest possible Friday (14th) and the earliest possible Sunday (16th).