Problem Submissions Solution

Cake Distribution Problem

Difficulty: Hard

Acceptance: %

Points: 40.00

John is hosting a birthday party, and his friends have brought him a cake with N chunks, where each chunk has a certain level of sweetness represented by an array. To share the cake, John cuts it into K + 1 pieces, one for each of his K friends and one for himself. Since John is considerate, he decides to take the piece with the minimum sweetness for himself. Your task is to determine the maximum possible sweetness that John can receive when he distributes the cake in this way.

You need to complete the maxSweetness() function which takes an integer array of sweetness, an integer N and an integer K as the input parameters and returns an integer denoting the maximum sweetness that the John can get.

Topics

Companies

Articles

Examples:

Expected Time Complexity: O(NlogM), where M is the sum of elements in the array.

Expected Space Complexity: O(1)

Constraints:
  • 1 <= N <= 10^5
  • 0 <= K < N
  • 1 <= sweetness[i] <= 10^9
Companies:
Microsoft Walmart Qualcomm
Topics:
Array Searching Algorithms
Locked Content
Access Restricted: Please Login to access the code editor and test cases.