<jupyter_start><jupyter_text>Minimized max sum of k partitionsGiven an array of numbers and an integer K, split the array into K partitions such that the maximum sum of any partition is minimized. Return the sum.Sample input:```array = [5, 1, 2, 7, 3, 4]  k = 3```Output:```Return 8since the optimal partition is [5, 1, 2], [7], [3, 4]```  Approach- We know that the sum can't be smaller than the largest element in the list- It also can't be largest than the sum of the whole listWe can check each value between the max element and the array sum until we find the smallest one that works. To make the search better, we can perform a binary search.<jupyter_code>def max_partition_sum(array, k):
    left, right = max(array), sum(array)
    
    while left < right:
        mid = (left + right) // 2
        if can_partition(array, mid, k):
            right = mid
        else:
            left = mid + 1
    return left

def can_partition(array, limit, k):
    total = 0
    partitions = 1
    
    for num in array:
        if total + num > limit:
            
            total = num
            partitions += 1
            if partitions > k:
                return False
        else:
            total += num
    return True
max_partition_sum(
    array=[5, 1, 2, 7, 3, 4],
    k=3
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08573596358118361, 'fraction_numerical': 0.019726858877086494, 'mean_word_length': 2.364795918367347, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '53800', 'license': 'MIT', 'n_tokens_mistral': 412, 'n_tokens_neox': 378, 'n_words': 176, 'path': 'arrays/max_sum_k_partitions_minimized.ipynb', 'repo_name': 'codacy-badger/algorithms-1', 'size': '1318'}