left
to the maximum element in nums
and right
to the sum of all elements in nums
.left
is less than or equal to right
, perform the following steps:
a. Calculate mid
as the average of left
and right
.
b. Determine if it's possible to split nums
into k
or fewer subarrays where each subarray sum is no greater than mid
.
c. If it is possible, update right
to mid - 1
and record mid
as a potential answer.
d. If it is not possible, update left
to mid + 1
.