I have a list of Booking
which contains startDate
and endDate
. I have to find the day which is the busiest in terms of bookings.
class Booking {
Date startDate;
Date endDate;
}
Example:
2016-10-12 to 2016-10-18
2016-10-11 to 2016-10-15
2016-10-13 to 2016-10-14
2016-10-12 to 2016-10-13
From these dates, it is obvious that 2016-10-13 was booked on all 4 times.
The solution that comes to my mind is:
- iterate through all the dates from minimum startDate to maximum endDate in the list
- keep a count of all number of bookings on all dates.
- finally, return the date having maximum count.
But this is not the efficient solution. How can I find busiest day efficiently?