Compare current value with maximum and minimum values up to previous index
prefix [ i , 0 ] = Math . Max ( prefix [ i - 1 , 0 ] , arr [ i ] ) ; prefix [ i , 1 ] = Math . Min ( prefix [ i - 1 , 1 ] , arr [ i ] ) ; } } }