Leetcode Problem 2409. Count Days Spent Together

2409. Count Days Spent Together

Leetcode Solutions

Calculate Overlapping Days

  1. Define an array representing the number of days in each month for a non-leap year.
  2. Create a function to convert a date in 'MM-DD' format to the day number of the year.
  3. Use the function to convert all four dates to day numbers.
  4. Find the later of the two arrival dates (the maximum start date).
  5. Find the earlier of the two departure dates (the minimum end date).
  6. Calculate the number of overlapping days as the difference between the minimum end date and the maximum start date plus one.
  7. If the maximum start date is greater than the minimum end date, return 0, as there is no overlap.
  8. Otherwise, return the number of overlapping days.
UML Thumbnail

Line Sweep Technique

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...