


‘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.
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.
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.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10^2
1 <= ‘N’ <= 5*10^3
0 <= ‘MEETINGS[i]’ <= 10^5 {each multiple of 15}
Time Limit: 1 second
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 previous meeting, then he has only one choice that is he has to skip the current meeting.
Here is the algorithm:
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 minutes for all meetings till now.
Here is the algorithm:
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:
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:
Here is the algorithm: