Minimize the Largest Part Beauty
Problem statement
Split the array nums into exactly k contiguous, non-empty parts. The beauty of a part is its largest value times its length.
Among all ways to split, return the smallest possible value of the largest beauty of a part.
Function
minMaxBeauty(nums: int[], k: int) → intExamples
Example 1
nums = [3,1,4,1,5]k = 2return = 12Split into [3, 1, 4] and [1, 5]: beauties 4 × 3 = 12 and 5 × 2 = 10, so the largest is 12. Other splits do worse, for example [3, 1] and [4, 1, 5] give 6 and 15. The answer is 12.
Example 2
nums = [2,2,2,2]k = 4return = 2With 4 parts every part is one value: each beauty is 2.
Example 3
nums = [1,9,1]k = 1return = 27One part holds everything: 9 × 3 = 27.
Constraints
1 <= k <= nums.length <= 10001 <= nums[i] <= 10^5