Minimize prize count required such that smaller value gets less prize in an adjacent pair | Function to find the minimum number of required such that adjacent smaller elements gets less number of prizes ; Loop to iterate over every elements of the array ; Loop to find the consecutive smaller elements at left ; Loop to find the consecutive smaller elements at right ; Driver code
def findMinPrizes ( arr , n ) : NEW_LINE INDENT totalPrizes = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT x = 1 NEW_LINE j = i NEW_LINE while ( j > 0 and arr [ j ] > arr [ j - 1 ] ) : NEW_LINE INDENT x += 1 NEW_LINE j -= 1 NEW_LINE DEDENT j = i NEW_LINE y = 1 NEW_LINE while ( j < n - 1 and arr [ j ] > arr [ j + 1 ] ) : NEW_LINE INDENT y += 1 NEW_LINE j += 1 NEW_LINE DEDENT totalPrizes += max ( x , y ) NEW_LINE DEDENT print ( totalPrizes ) NEW_LINE DEDENT arr = [ 1 , 2 , 2 , 3 ] NEW_LINE n = len ( arr ) NEW_LINE findMinPrizes ( arr , n ) NEW_LINE