Backward traversal
while ( sBackward . length != 0 && arr [ n - i - 1 ] < arr [ sBackward [ sBackward . length - 1 ] ] ) { ans = Math . max ( ans , arr [ n - i - 1 ] ^ arr [ sBackward [ sBackward . length - 1 ] ] ) ; sBackward . pop ( ) ; } sBackward . push ( n - i - 1 ) ; } return ans ; }