I really like Ruby for binary search...

```
def split_array(nums, m)
(nums.max .. nums.inject(:+)).bsearch { |cap|
subarrays = 0
sum = cap
nums.each { |num|
if (sum += num) > cap
sum = num
subarrays += 1
end
}
subarrays <= m
}
end
```

If we can do it with a certain cap like 9 in the example, we can of course also do it with any larger cap. Meaning we can use binary search. And we want to know the smallest cap possible.

For the binary search, we just need to be able to determine for a certain cap whether it's ok. Meaning whether we can split the array into m subarrays so that no subarray's sum is over this cap. To do that, we determine the **minimum** number of subarrays we can do with this cap. If it's smaller than or equal to m, this cap is ok. Wait, aren't we supposed to create **exactly** m subarrays? Yeah, but if we can do it with fewer, we can just split some up so we have exactly m.

So how to find the minimum number of subarrays we can do with a certain cap? We can do that greedily. Of course it's smart to stuff as many numbers into the first subarray as we can - then we don't need to try to fit them into the remaining subarrays. Same for the remaining subarrays - always stuff as many numbers into them as we can, only start a new subarray when the current number doesn't still fit into the previous subarray.

The initial range for possible caps is from the maximum in `nums`

(because with a lower cap, we couldn't fit that number into any subarray) to the sum of `nums`

(a larger cap would be useless - we'll never need more room than all numbers combined).