Loop to find the consecutive smaller elements at right
while ( j < n - 1 && arr [ j ] > arr [ j + 1 ] ) { y ++ ; j ++ ; } totalPrizes += Math . max ( x , y ) ; } document . write ( totalPrizes ) ; return 0 ; }