java.lang.Object
g0801_0900.s0813_largest_sum_of_averages.Solution

public class Solution extends Object
813 - Largest Sum of Averages.<p>Medium</p> <p>You are given an integer array <code>nums</code> and an integer <code>k</code>. You can partition the array into <strong>at most</strong> <code>k</code> non-empty adjacent subarrays. The <strong>score</strong> of a partition is the sum of the averages of each subarray.</p> <p>Note that the partition must use every integer in <code>nums</code>, and that the score is not necessarily an integer.</p> <p>Return <em>the maximum <strong>score</strong> you can achieve of all the possible partitions</em>. Answers within <code>10<sup>-6</sup></code> of the actual answer will be accepted.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [9,1,2,3,9], k = 3</p> <p><strong>Output:</strong> 20.00000</p> <p><strong>Explanation:</strong></p> <p>The best choice is to partition nums into [9], [1, 2, 3], [9]. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.</p> <p>We could have also partitioned nums into [9, 1], [2], [3, 9], for example.</p> <p>That partition would lead to a score of 5 + 2 + 6 = 13, which is worse.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [1,2,3,4,5,6,7], k = 4</p> <p><strong>Output:</strong> 20.50000</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 100</code></li> <li><code>1 <= nums[i] <= 10<sup>4</sup></code></li> <li><code>1 <= k <= nums.length</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • largestSumOfAverages

      public double largestSumOfAverages(int[] nums, int k)