Ninja and his meetings

Ninja has recently started a startup. In his startup, there is only one conference room for a meeting. Ninja receives an array/list ‘MEETINGS’ of back-to-back appointment requests and is debating which ones to accept. Ninja needs a 15-minute break between appointments, and therefore he cannot accept any adjacent requests.

Ninja has to find the highest total booked minutes in the conference room for all meetings.

Note: All meeting timings are multiples of 15.

For example:

‘MEETINGS[]’ = {30, 15, 60}

Let us assume the meeting starts at 12:00 o’clock.
The first meeting takes 30 minutes so after the first meeting time is 12:30.
Then Ninja cannot attend the second meeting which is for 15 minutes because he needs 15 minutes break after every meeting.
After a 15 minutes break, he can attend the next meeting which is for 60 minutes.

So the total booked minutes for the meetings is 30 + 60 = 90.
Input Format
The first line of input contains an integer ‘T’ which denotes the number of test cases or queries to be run. Then the test cases follow.

The first line of each test case contains an integer ‘N’ represents the number of meetings.

The next line of each test case contains ‘N’ single space-separated integers denoting the time taken by a meeting.
Output Format :
For each test case, return the number of minutes for all meetings which are scheduled.

Print the output of each test case in a separate line.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
Constraints:
1 <= ‘T’ <= 10^2
1 <= ‘N’ <= 5*10^3
0 <= ‘MEETINGS[i]’ <= 10^5 {each multiple of 15}

Time Limit: 1 second
CodingNinjas
author
2y
Recursion

As we know if Ninja skips the previous meeting, then he has two choices for the current meeting, that is he can either schedule this meeting or he can skip this meeting.

If Ninja schedules the...read more

CodingNinjas
author
2y
Memoization

As we know in our previous approach there are a lot of repeating function calls. So we can optimize our recursive approach by using a ‘MEMO’ array/list. In ‘MEMO[i]’ we are storing the max ...read more

CodingNinjas
author
2y
Dynamic Programming

We can optimize our above approach by using a ‘DP’ array/list also. In ‘DP[i]’ we are storing the max minutes for all meetings till now.

Here is the algorithm:

  1. We declare a ‘DP’ arra...read more
CodingNinjas
author
2y
Iterative

We know Ninja can not accept any adjacent requests. Using this fact, we can optimize our above solution. For finding the highest total booked minutes till now we have only two ways:

  1. We includ...read more
Add answer anonymously...
Atlassian Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter