Find minimum value from right for every index
let n = arr . length ; let right_min = new Array ( n + 1 ) ; right_min . fill ( 0 ) ; right_min [ n ] = Number . MAX_VALUE ; for ( let i = n - 1 ; i >= 0 ; i -- ) { right_min [ i ] = Math . min ( right_min [ i + 1 ] , arr [ i ] ) ; }