Statistics

Problem Statement for "SaturdayNightStay"

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

  1. 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.

  2. 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.

  3. 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.)

  4. 7

    8

    19

    10

    Returns: 2485

  5. 1

    1

    31

    12

    Returns: 65346

  6. 3

    6

    18

    7

    Returns: 905

  7. 9

    6

    19

    8

    Returns: 2345

  8. 20

    7

    13

    9

    Returns: 1378

  9. 26

    1

    22

    7

    Returns: 15227

  10. 31

    1

    1

    2

    Returns: 0

  11. 31

    5

    24

    8

    Returns: 3402

  12. 19

    6

    1

    9

    Returns: 2559

  13. 17

    4

    8

    7

    Returns: 3165

  14. 31

    8

    12

    9

    Returns: 47

  15. 2

    4

    12

    9

    Returns: 12884

  16. 20

    6

    23

    12

    Returns: 16841

  17. 18

    6

    25

    10

    Returns: 8003

  18. 8

    4

    30

    12

    Returns: 34718

  19. 5

    1

    4

    6

    Returns: 10881

  20. 19

    6

    17

    7

    Returns: 331

  21. 4

    5

    27

    9

    Returns: 10296

  22. 30

    4

    28

    11

    Returns: 21949

  23. 7

    6

    28

    12

    Returns: 20300

  24. 25

    2

    24

    8

    Returns: 15750

  25. 22

    6

    20

    7

    Returns: 322

  26. 26

    4

    29

    5

    Returns: 470

  27. 12

    5

    30

    9

    Returns: 9590

  28. 16

    1

    19

    9

    Returns: 29651

  29. 19

    5

    9

    7

    Returns: 1176

  30. 20

    4

    17

    12

    Returns: 28444

  31. 21

    2

    13

    4

    Returns: 1176

  32. 9

    8

    30

    10

    Returns: 3165

  33. 1

    8

    5

    9

    Returns: 533

  34. 18

    3

    26

    11

    Returns: 31378

  35. 3

    2

    17

    5

    Returns: 5047

  36. 26

    8

    18

    10

    Returns: 1275

  37. 20

    1

    12

    7

    Returns: 14532

  38. 29

    5

    20

    11

    Returns: 14884

  39. 30

    8

    22

    9

    Returns: 212

  40. 27

    6

    21

    12

    Returns: 15225

  41. 19

    1

    7

    4

    Returns: 2850

  42. 14

    6

    6

    12

    Returns: 14880

  43. 16

    3

    5

    4

    Returns: 153

  44. 5

    2

    26

    12

    Returns: 51685

  45. 13

    9

    12

    10

    Returns: 350

  46. 9

    2

    1

    8

    Returns: 14537

  47. 3

    7

    4

    11

    Returns: 7386

  48. 2

    5

    1

    6

    Returns: 378

  49. 6

    3

    17

    12

    Returns: 40192

  50. 7

    8

    17

    8

    Returns: 28

  51. 19

    8

    1

    10

    Returns: 823

  52. 27

    3

    3

    12

    Returns: 30882

  53. 30

    3

    11

    9

    Returns: 13206

  54. 29

    1

    28

    11

    Returns: 45154

  55. 8

    10

    2

    12

    Returns: 1382

  56. 14

    1

    18

    1

    Returns: 0

  57. 15

    1

    19

    1

    Returns: 0

  58. 8

    1

    8

    1

    Returns: 0

  59. 29

    1

    3

    2

    Returns: 5

  60. 30

    1

    1

    2

    Returns: 0

  61. 5

    2

    11

    2

    Returns: 10

  62. 17

    2

    18

    2

    Returns: 0

  63. 23

    2

    28

    2

    Returns: 5

  64. 28

    2

    3

    3

    Returns: 3

  65. 26

    2

    3

    3

    Returns: 5

  66. 12

    3

    18

    3

    Returns: 10

  67. 19

    3

    25

    3

    Returns: 10

  68. 13

    3

    16

    3

    Returns: 0

  69. 29

    3

    2

    4

    Returns: 6

  70. 28

    3

    1

    4

    Returns: 6

  71. 21

    4

    26

    4

    Returns: 0

  72. 3

    4

    9

    4

    Returns: 12

  73. 7

    4

    12

    4

    Returns: 0

  74. 29

    4

    2

    5

    Returns: 0

  75. 28

    4

    3

    5

    Returns: 0

  76. 4

    5

    9

    5

    Returns: 5

  77. 5

    5

    6

    5

    Returns: 0

  78. 25

    5

    26

    5

    Returns: 1

  79. 29

    5

    1

    6

    Returns: 0

  80. 30

    5

    1

    6

    Returns: 0

  81. 1

    6

    3

    6

    Returns: 2

  82. 19

    6

    25

    6

    Returns: 12

  83. 15

    6

    21

    6

    Returns: 6

  84. 30

    6

    4

    7

    Returns: 0

  85. 30

    6

    1

    7

    Returns: 0

  86. 25

    7

    31

    7

    Returns: 12

  87. 16

    7

    17

    7

    Returns: 0

  88. 8

    7

    12

    7

    Returns: 0

  89. 31

    7

    3

    8

    Returns: 0

  90. 30

    7

    3

    8

    Returns: 0

  91. 18

    8

    24

    8

    Returns: 0

  92. 27

    8

    30

    8

    Returns: 0

  93. 20

    8

    24

    8

    Returns: 0

  94. 31

    8

    4

    9

    Returns: 4

  95. 30

    8

    1

    9

    Returns: 2

  96. 9

    9

    11

    9

    Returns: 0

  97. 22

    9

    28

    9

    Returns: 0

  98. 19

    9

    23

    9

    Returns: 6

  99. 29

    9

    4

    10

    Returns: 0

  100. 30

    9

    1

    10

    Returns: 0

  101. 2

    10

    8

    10

    Returns: 12

  102. 15

    10

    21

    10

    Returns: 10

  103. 14

    10

    14

    10

    Returns: 0

  104. 29

    10

    1

    11

    Returns: 0

  105. 31

    10

    5

    11

    Returns: 9

  106. 17

    11

    17

    11

    Returns: 0

  107. 11

    11

    14

    11

    Returns: 0

  108. 24

    11

    30

    11

    Returns: 0

  109. 29

    11

    4

    12

    Returns: 8

  110. 29

    11

    1

    12

    Returns: 2

  111. 23

    12

    28

    12

    Returns: 0

  112. 17

    12

    20

    12

    Returns: 0

  113. 4

    12

    8

    12

    Returns: 4


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: