Company: Oracle_19aug
Difficulty: medium
Maximize Array Value Problem Description You are given a 1-indexed array of n positive integers. You may repeatedly apply the following move, as many times as you like: Choose any index i where 2 ≤ i ≤ n Choose any value x where 1 ≤ x ≤ arr[i] Set arr[i-1] to arr[i-1] + x Set arr[i] to arr[i] - x Using any sequence of such moves, drive the largest value in the array as low as possible, and return that lowest achievable maximum. Examples Example 1: Consider the array arr = [1, 5, 7, 6] with n = 4 . One sequence of moves that reaches the optimum: Move 1: Choose i = 3, x = 4 Replace arr[2] with 5 + 4 = 9 Replace arr[3] with 7 - 4 = 3 Array becomes [1, 9, 3, 6] with maximum 9 Move 2: Choose i = 2, x = 4 Replace arr[1] with 1 + 4 = 5 Replace arr[2] with 9 - 4 = 5 Array becomes [5, 5, 3, 6] with maximum 6 Move 3: Choose i = 4, x = 1 Replace arr[3] with 3 + 1 = 4 Replace arr[4] with 6 - 1 = 5 Array becomes [5, 5, 4, 5] with maximum 5 No sequence of moves can push the maximum below