Problem Statement
Basha promised her friend Mel that she will come for a visit somewhere between the firstDay of the firstMonth and the lastDay of the lastMonth in 2019. Basha and Mel live in countries separated by the sea, so Basha has to buy plane tickets.
Airlines are using many tricks when pricing their tickets. One of the important ones is the "Saturday night stay" concept: if your stay at the destination includes the night from a Saturday to a Sunday, you are unlikely to be a business traveler and thus they will give you a lower price for your tickets. Basha would like to have cheap plane tickets (who wouldn't), so she wants to plan her trip in such a way that it will include at least one Saturday night.
To summarize:
- Basha's day of arrival must be on the firstDay of the firstMonth 2019 or later.
- Basha's day of departure must be on the lastDay of the lastMonth 2019 or earlier.
- Basha must stay at Mel's place for at least one Saturday night.
Two trip schedules are considered different if Basha arrives and/or departs on a different day. Count all possible trip schedules, and return the answer.
Definition
- Class:
- SaturdayNightStay
- Method:
- countOptions
- Parameters:
- int, int, int, int
- Returns:
- int
- Method signature:
- int countOptions(int firstDay, int firstMonth, int lastDay, int lastMonth)
- (be sure your method is public)
Notes
- The year 2019 is not a leap year. The number of days in the individual months of 2019 is 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, and 31.
- The 1st of January 2019 was a Tuesday.
- As explained in the statement, "Saturday night" is short for "the night that starts on a Saturday and ends on a Sunday".
Constraints
- firstMonth and lastMonth will each be between 1 and 12, inclusive.
- firstDay will be between 1 and the number of days in firstMonth, inclusive.
- lastDay will be between 1 and the number of days in lastMonth, inclusive.
- The firstDay of the firstMonth will not be later in 2019 than the lastDay of the lastMonth.
Examples
15
6
16
6
Returns: 1
The earliest day on which Basha can arrive is today: the 15th of June. This is a Saturday. The latest day on which she can leave is the 16th of June: the Sunday tomorrow. In order to spend the Saturday night in her destination, Basha must arrive on the 15th and depart on the 16th.
16
6
22
6
Returns: 0
Regardless of when she arrives and departs, her trip will not include any Saturday nights. Note that the trip which arrives on the 16th and departs on the 22nd includes both a Saturday (the 22nd) and a Sunday (the 16th) but that is not enough: the trip does not contain any Saturday night.
1
1
31
1
Returns: 382
There are many viable options in January 2019, including the longest one: arriving on the 1st and departing on the 31st of January. (This trip contains four different Saturday nights. Additional Saturday nights do not matter, the only requirement is that there has to be at least one of them.)
7
8
19
10
Returns: 2485
1
1
31
12
Returns: 65346
3
6
18
7
Returns: 905
9
6
19
8
Returns: 2345
20
7
13
9
Returns: 1378
26
1
22
7
Returns: 15227
31
1
1
2
Returns: 0
31
5
24
8
Returns: 3402
19
6
1
9
Returns: 2559
17
4
8
7
Returns: 3165
31
8
12
9
Returns: 47
2
4
12
9
Returns: 12884
20
6
23
12
Returns: 16841
18
6
25
10
Returns: 8003
8
4
30
12
Returns: 34718
5
1
4
6
Returns: 10881
19
6
17
7
Returns: 331
4
5
27
9
Returns: 10296
30
4
28
11
Returns: 21949
7
6
28
12
Returns: 20300
25
2
24
8
Returns: 15750
22
6
20
7
Returns: 322
26
4
29
5
Returns: 470
12
5
30
9
Returns: 9590
16
1
19
9
Returns: 29651
19
5
9
7
Returns: 1176
20
4
17
12
Returns: 28444
21
2
13
4
Returns: 1176
9
8
30
10
Returns: 3165
1
8
5
9
Returns: 533
18
3
26
11
Returns: 31378
3
2
17
5
Returns: 5047
26
8
18
10
Returns: 1275
20
1
12
7
Returns: 14532
29
5
20
11
Returns: 14884
30
8
22
9
Returns: 212
27
6
21
12
Returns: 15225
19
1
7
4
Returns: 2850
14
6
6
12
Returns: 14880
16
3
5
4
Returns: 153
5
2
26
12
Returns: 51685
13
9
12
10
Returns: 350
9
2
1
8
Returns: 14537
3
7
4
11
Returns: 7386
2
5
1
6
Returns: 378
6
3
17
12
Returns: 40192
7
8
17
8
Returns: 28
19
8
1
10
Returns: 823
27
3
3
12
Returns: 30882
30
3
11
9
Returns: 13206
29
1
28
11
Returns: 45154
8
10
2
12
Returns: 1382
14
1
18
1
Returns: 0
15
1
19
1
Returns: 0
8
1
8
1
Returns: 0
29
1
3
2
Returns: 5
30
1
1
2
Returns: 0
5
2
11
2
Returns: 10
17
2
18
2
Returns: 0
23
2
28
2
Returns: 5
28
2
3
3
Returns: 3
26
2
3
3
Returns: 5
12
3
18
3
Returns: 10
19
3
25
3
Returns: 10
13
3
16
3
Returns: 0
29
3
2
4
Returns: 6
28
3
1
4
Returns: 6
21
4
26
4
Returns: 0
3
4
9
4
Returns: 12
7
4
12
4
Returns: 0
29
4
2
5
Returns: 0
28
4
3
5
Returns: 0
4
5
9
5
Returns: 5
5
5
6
5
Returns: 0
25
5
26
5
Returns: 1
29
5
1
6
Returns: 0
30
5
1
6
Returns: 0
1
6
3
6
Returns: 2
19
6
25
6
Returns: 12
15
6
21
6
Returns: 6
30
6
4
7
Returns: 0
30
6
1
7
Returns: 0
25
7
31
7
Returns: 12
16
7
17
7
Returns: 0
8
7
12
7
Returns: 0
31
7
3
8
Returns: 0
30
7
3
8
Returns: 0
18
8
24
8
Returns: 0
27
8
30
8
Returns: 0
20
8
24
8
Returns: 0
31
8
4
9
Returns: 4
30
8
1
9
Returns: 2
9
9
11
9
Returns: 0
22
9
28
9
Returns: 0
19
9
23
9
Returns: 6
29
9
4
10
Returns: 0
30
9
1
10
Returns: 0
2
10
8
10
Returns: 12
15
10
21
10
Returns: 10
14
10
14
10
Returns: 0
29
10
1
11
Returns: 0
31
10
5
11
Returns: 9
17
11
17
11
Returns: 0
11
11
14
11
Returns: 0
24
11
30
11
Returns: 0
29
11
4
12
Returns: 8
29
11
1
12
Returns: 2
23
12
28
12
Returns: 0
17
12
20
12
Returns: 0
4
12
8
12
Returns: 4