Input: array: [2, 3, 5, 9, 14], max allowed sum per subarray = 10; find minimum largest sum to split array into subarrays
Goal: Find the smallest maximum sum possible when splitting the array into subarrays so that no subarray sum exceeds this value
Step 1: Set low to max element 14, high to sum 33, guess mid = (14+33)/2 = 23
low=14, mid=23, high=33 Why: We start searching between the largest single element and total sum
Step 2: Check if array can be split with max subarray sum ≤ 23
Subarrays: [2,3,5,9] sum=19 ≤ 23, [14] sum=14 ≤ 23 Why: 23 works because we can split into 2 subarrays without exceeding 23
Step 3: Since 23 works, try smaller max sum by setting high = mid = 23
low=14, high=23 Why: Try to find smaller max sum to optimize answer
Step 4: Guess mid = (14+23)/2 = 18, check feasibility
Check subarrays with max sum ≤ 18 Why: Test if smaller max sum 18 is possible
Step 5: Split: [2,3,5,9] sum=19 > 18, so split earlier: [2,3,5] sum=10 ≤ 18, next subarray [9,14] sum=23 > 18
Cannot split into valid subarrays with max sum ≤ 18 Why: 18 too small, need to increase low
Step 6: Set low = mid + 1 = 19
low=19, high=23 Why: Increase low to find feasible max sum
Step 7: Guess mid = (19+23)/2 = 21, check feasibility
Check subarrays with max sum ≤ 21 Step 8: Split: [2,3,5,9] sum=19 ≤ 21, [14] sum=14 ≤ 21, works
Feasible with max sum 21 Why: Try smaller max sum by setting high = 21
Step 9: Set high = 21
low=19, high=21 Why: Try to find smaller max sum
Step 10: Guess mid = (19+21)/2 = 20, check feasibility
Check subarrays with max sum ≤ 20 Step 11: Split: [2,3,5,9] sum=19 ≤ 20, [14] sum=14 ≤ 20, works
Feasible with max sum 20 Why: Try smaller max sum by setting high = 20
Step 12: Set high = 20
low=19, high=20 Why: Try to find smaller max sum
Step 13: Guess mid = (19+20)/2 = 19, check feasibility
Check subarrays with max sum ≤ 19 Step 14: Split: [2,3,5,9] sum=19 ≤ 19, [14] sum=14 ≤ 19, works
Feasible with max sum 19 Why: Try smaller max sum by setting high = 19
Step 15: Set high = 19
low=19, high=19 Why: low equals high, search ends
Result: Final answer: 19
Array split with max subarray sum 19: [2,3,5,9] and [14]