Ctrl K

Shared Vacation Days

Easy
Two friends are vacationing in the same seaside town. The first stays from first_in to first_out inclusive, the second from second_in to second_out inclusive. Each date is a string "MM-DD" (month and day). Count the days both friends are in town at the same time. All dates fall in the same non-leap year. The month lengths are [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31].
Example 1
first_in="07-28", first_out="08-03", second_in="08-01", second_out="08-10" → 3

They are both at the seaside on August 1, 2 and 3: three days.

Example 2
first_in="02-27", first_out="03-02", second_in="02-20", second_out="03-31" → 4

The year is not a leap year: February 27 and 28, then March 1 and 2, four days.

Example 3
first_in="05-01", first_out="05-10", second_in="05-11", second_out="05-20" → 0

The second friend arrives the day after the first one leaves, so they share no days.

Constraints
  • Every date is in the "MM-DD" format and exists in a non-leap year
  • first_in ≤ first_out, second_in ≤ second_out
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasySum of Binary Strings EasySpreadsheet Column Label EasySpreadsheet Column Index EasyCounting Off by Threes and Fives Easy
loading Python…
Input
first_in="07-28", first_out="08-03", second_in="08-01", second_out="08-10"
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 115 tests on the server, hidden ones included.