#3077
Maximum Strength of K Disjoint Subarrays
international master · 2065 · lc hard +32 · 27.5% accepted · 175 likes · top 5%
Description
Given an integer array nums and a positive odd integer k, choose exactly k non-overlapping subarrays in left-to-right order. Their combined strength is:strength = k * sum(sub1) - (k - 1) * sum(sub2) + (k - 2) * sum(sub3) - ... + sum(subk)
The subarrays need not cover nums entirely. Return the maximum achievable strength.
Code
1
2
3