#403 Choosing a Vacation with the Fewest Missed Meetings

Companies:
Avito
Themes:
AlgorithmsArraysPractice

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.

Text
# 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]
Text
# 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

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in