<p>Given an integer array <code>nums</code> and an integer <code>k</code>, split <code>nums</code> into <code>k</code> non-empty subarrays such that the largest sum of any subarray is <strong>minimized</strong>.</p>

<p>Return <em>the minimized largest sum of the split</em>.</p>

<p>A <strong>subarray</strong> is a contiguous part of the array.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [7,2,5,10,8], k = 2
<strong>Output:</strong> 18
<strong>Explanation:</strong> There are four ways to split nums into two subarrays.
The best way is to split it into [7,2,5] and [10,8], where the largest sum among the two subarrays is only 18.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3,4,5], k = 2
<strong>Output:</strong> 9
<strong>Explanation:</strong> There are four ways to split nums into two subarrays.
The best way is to split it into [1,2,3] and [4,5], where the largest sum among the two subarrays is only 9.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 1000</code></li>
	<li><code>0 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
	<li><code>1 &lt;= k &lt;= min(50, nums.length)</code></li>
</ul>

# 1 <= k <= len(nums), nums >= 0 integers.
# split into k non-empty subarrays with minimal sum, return this minimal sum.
# - brute force doesn't work
# - some kind of dp? <- would need cur_min, cur_chunk, pos surely?
# - maybe consider if a possible minimum m is attainable (!)
# - m is in the [0, len(nums) * max(nums) = M] range. (log(M) reasonable size)
# - believe an O(N) check on m is possible, just expand the current chunk until
# it goes above m.

class Solution:
    def checkMin(self, nums: List[int], k: int, m: int) -> bool:
        cur_sum, n_chunk = 0, 1
        for num in nums:
            if num > m:
                return False
            if cur_sum + num > m:
                n_chunk += 1
                cur_sum = num
            else:
                cur_sum += num
        return n_chunk <= k

    def splitArray(self, nums: List[int], k: int) -> int:
        l, r = 0, 10**9   # [l, r] range
        while l < r:
            m = (l + r) // 2
            if self.checkMin(nums, k, m):
                r = m
            else:
                l = m + 1
        return l

16200