2025-08-19 15:24:40 +0300 MSK
Count Days Spent Together
Links
Code
class Solution:
def countDaysTogether(self, arriveAlice: str, leaveAlice: str, arriveBob: str, leaveBob: str) -> int:
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def count(date: str) -> int:
month = int(date[:2])
days = int(date[3:])
return sum(months[:month - 1]) + days
return max(0, count(min(leaveAlice, leaveBob)) - count(max(arriveAlice, arriveBob)) + 1)