"Minimize largest sum of subarray split in 30DaysChallenge"

🔷 Day 28- 30DaysChallenge(Leetcode Problem): 🌟 Problem: Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized. Return the minimized largest sum of the split. A subarray is a contiguous part of the array.   🧠Solution:   class Solution:   def splitArray(self, nums: list[int], k: int) -> int:     low, high = max(nums), sum(nums)     def ok(x):       cnt, curr = 1, 0       for v in nums:         if curr + v <= x:           curr += v         else:           cnt += 1           curr = v           if cnt > k:             return False       return True             while low < high:       mid = (low + high) // 2       if ok(mid):         high = mid       else:         low = mid + 1     return low #DSA #Python #CodingChallenge #30dayschallenge #Leetcode

To view or add a comment, sign in

Explore content categories