Minimize maximum array element by splitting array elements into powers of two at most K times | Function to find the minimum value of the maximum element of the array by splitting at most K array element into perfect powers of 2 ; Sort the array element in the ascending order ; Reverse the array ; If count of 0 is equal to N ; Otherwise , if K is greater than or equal to N ; Otherwise ; Driver Code
def minimumSize ( arr , N , K ) : NEW_LINE INDENT arr . sort ( ) NEW_LINE arr . reverse ( ) NEW_LINE zero = arr . count ( 0 ) NEW_LINE if zero == N : NEW_LINE INDENT print ( 0 ) NEW_LINE DEDENT elif K >= N : NEW_LINE INDENT print ( 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( arr [ K ] ) NEW_LINE DEDENT DEDENT arr = [ 2 , 4 , 8 , 2 ] NEW_LINE K = 2 NEW_LINE N = len ( arr ) NEW_LINE minimumSize ( arr , N , K ) NEW_LINE