Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    813 - Largest Sum of Averages.

    Medium

    You are given an integer array nums and an integer k. You can partition the array into at most k non-empty adjacent subarrays. The score of a partition is the sum of the averages of each subarray.

    Note that the partition must use every integer in nums, and that the score is not necessarily an integer.

    Return the maximum score you can achieve of all the possible partitions. Answers within <code>10<sup>-6</sup></code> of the actual answer will be accepted.

    Example 1:

    Input: nums = 9,1,2,3,9, k = 3

    Output: 20.00000

    Explanation:

    The best choice is to partition nums into 9, 1, 2, 3, 9. The answer is 9 + (1 + 2 + 3) / 3 + 9 = 20.

    We could have also partitioned nums into 9, 1, 2, 3, 9, for example.

    That partition would lead to a score of 5 + 2 + 6 = 13, which is worse.

    Example 2:

    Input: nums = 1,2,3,4,5,6,7, k = 4

    Output: 20.50000

    Constraints:

    • 1 &lt;= nums.length &lt;= 100

    • <code>1 <= numsi<= 10<sup>4</sup></code>

    • 1 &lt;= k &lt;= nums.length

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Double largestSumOfAverages(IntArray nums, Integer k)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait