Leetcode 410 Solution
This article provides solution to leetcode question 410 (split-array-largest-sum)
Access this page by simply typing in "lcs 410" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/split-array-largest-sum
Solution
class Solution:
def canSplit(self, nums, m, s):
left = 0
needed = 0
for num in nums:
if num > left:
needed += 1
left = s
left -= num
return needed <= m
def splitArray(self, nums: List[int], m: int) -> int:
l = max(nums)
r = sum(nums)
while l < r:
mid = (l + r) // 2
if self.canSplit(nums, m, mid):
r = mid
else:
l = mid + 1
return l