Maximize the minimum array element by M subarray increments of size S | Function to return index of minimum element in the array ; Initialize a [ 0 ] as minValue ; Traverse the array ; If a [ i ] < existing minValue ; Return the minimum index ; Function that maximize the minimum element of array after incrementing subarray of size S by 1 , M times ; Iterating through the array for M times ; Find minimum element index ; Increment the minimum value ; Storing the left index and right index ; Incrementing S - 1 minimum elements to the left and right of minValue ; Reached extreme left ; Reached extreme right ; Left value is minimum ; Right value is minimum ; Find the minValue in A [ ] after M operations ; Return the minimum value ; Driver Code ; Function Call
def min ( a , n ) : NEW_LINE INDENT minIndex = 0 NEW_LINE minValue = a [ 0 ] NEW_LINE for i in range ( 1 , n ) : NEW_LINE INDENT if ( a [ i ] < minValue ) : NEW_LINE INDENT minValue = a [ i ] NEW_LINE minIndex = i NEW_LINE DEDENT DEDENT return minIndex NEW_LINE DEDENT def maximizeMin ( A , N , S , M ) : NEW_LINE INDENT minIndex , left , right = 0 , 0 , 0 NEW_LINE for i in range ( M ) : NEW_LINE INDENT minIndex = min ( A , N ) NEW_LINE A [ minIndex ] += 1 NEW_LINE left = minIndex - 1 NEW_LINE right = minIndex + 1 NEW_LINE for j in range ( S - 1 ) : NEW_LINE INDENT if ( left == - 1 ) : NEW_LINE INDENT A [ right ] += 1 NEW_LINE right += 1 NEW_LINE DEDENT elif ( right == N ) : NEW_LINE INDENT A [ left ] += 1 NEW_LINE left -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT if ( A [ left ] < A [ right ] ) : NEW_LINE INDENT A [ left ] += 1 NEW_LINE left -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT A [ right ] += 1 NEW_LINE right += 1 NEW_LINE DEDENT DEDENT DEDENT DEDENT minIndex = min ( A , N ) NEW_LINE return A [ minIndex ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 3 , 4 , 5 , 6 ] NEW_LINE N = len ( arr ) NEW_LINE S = 2 NEW_LINE M = 3 NEW_LINE print ( maximizeMin ( arr , N , S , M ) ) NEW_LINE DEDENT