#403 Choosing a Vacation with the Fewest Missed Meetings
There comes a time in everyone's life when it is necessary to go on vacation. But then we look at the calendar and realize that many meetings are coming up and we do not want to miss them.
Determine the vacation start day X for a vacation lasting V days so that the entire vacation fits within the next P days and the number Y of missed meetings is minimized. Tomorrow is considered the first possible vacation day, with day: 1.
# Example 1
# input
daysWithMeetings = [{ day: 3, meetings: 1 }, { day: 4, meetings: 3 }, { day: 14, meetings: 3 }, { day: 21, meetings: 3 }, { day: 28, meetings: 1 },] # meeting days are already sorted
periodLength = 30 # the entire vacation must fit within this period, in this example within the next 30 days
vacationLength = 7
# output
[5, 0] # [vacation start day X, number of meetings Y that will be missed]# Example 2
# input
daysWithMeetings = [{ day: 3, meetings: 1 }, { day: 4, meetings: 3 }, { day: 5, meetings: 3 }, { day: 9, meetings: 5 }, { day: 13, meetings: 2 }, { day: 14, meetings: 1 }, { day: 21, meetings: 3 }, { day: 25, meetings: 3 }, { day: 28, meetings: 6 },]
periodLength = 31
vacationLength = 14
# output
[10, 6] # [how many days until the vacation starts, how many meetings will be missed]Question review
Sign in to start the dialogue
The mentor keeps the context of the current question and your previous messages.
Sign in
Available with Premium
This is just one of the solutions available with Premium. And more:
- 250+ advanced lectures
- 1300+ practice exercises
- 500+ solutions to problems from real interviews
- Personalized Java Hub certificates
- Expanded access to the AI mentor