#2409

Count Days Spent Together

pupil · 515 · lc easy +28 · verified · 47.7% accepted · 283 likes · top 33%

Description

Alice and Bob both travel to Rome, with their visits described by four strings: arriveAlice, leaveAlice, arriveBob, and leaveBob, each in the format "MM-DD".

Count the number of days both Alice and Bob are in Rome at the same time.

You may assume the year is not a leap year, and all months have the day counts of a standard non-leap year.

Example 1:

Input: arriveAlice = "08-15", leaveAlice = "08-18", arriveBob = "08-16", leaveBob = "08-19"
Output: 3
Explanation: Alice will be in Rome from August 15 to August 18. Bob will be in Rome from August 16 to August 19. They are both in Rome together on August 16th, 17th, and 18th, so the answer is 3.

Example 2:

Input: arriveAlice = "10-01", leaveAlice = "10-31", arriveBob = "11-01", leaveBob = "12-31"
Output: 0
Explanation: There is no day when Alice and Bob are in Rome together, so we return 0.

Code

1
2
3