Divide Chocolates
Ninja bought chocolate consisting of some chunks. The sweetness of each chunk is given in an array ‘ARR’. Ninja has ‘K’ friends, and he wishes to divide the chocolate into 'K' + 1 cut with some consecutive chunks. He wants to divide the chocolate into chunks under the condition that he will take the piece that has the minimum total sweetness.
He is very busy doing other stuff. Can you help him to maximize the total sweetness of the part that you will get under the given condition?
Input Format:
The first line of input contains an integer ‘T’, denoting the number of test cases. Then the test cases follow.
The first line of each test case contains two space-separated integers, ‘N’ and ‘K’, denoting the size of array ‘ARR’ and the number of friends Ninja has.
The second line of each test case contains ‘N’ space-separated integers denoting the elements of the array ‘ARR’.
Output Format:
For each test case, print the maximum sweetness that Ninja can get under the given condition.
Print the output of each test case in a new line.
Note:
You are not required to print the expected output, it has already been taken care of. Just implement the function.
Constraints:
1<= T <= 10
1 <= N <= 50000
0 <= K < N
1 <= ARR[i] <= 10000
Where 'ARR[i]' is the sweetness of the ‘i_th' chunk.
Time Limit: 1 sec
CodingNinjas
author
2y
Dynamic Programming
The idea is to figure out the recursive calls and optimize them using dynamic programming.
It breaks down into a problem of dividing the array into ‘K’ + 1 partitions such that the p...read more
CodingNinjas
author
2y
Binary Search
The idea is to find the range in which the minimum sweetness can lie and then iterate in the given range and find the maximum sweetness you can have. The minimum value possible of sweetne...read more
Help your peers!
Add answer anonymously...
Top Kellton Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Kellton Software Engineer
Stay ahead in your career. Get AmbitionBox app
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