Vector to store the left and right index for each i such that left [ i ] > arr [ i ] and right [ i ] > arr [ i ]
let left = new Array ( n ) . fill ( 0 ) , right = new Array ( n ) . fill ( 0 ) ; let s = [ ] ; s . push ( [ Number . MAX_SAFE_INTEGER , - 1 ] ) ;