• + 0 comments

    My JS Solution

    function andXorOr(A) {
        var stack = [A[0], A[1]];
        var S = A[0] ^ A[1];
        
        for(let i = 2; i < A.length; i++){
            while(stack.length > 0 && stack.slice(-1) >= A[i]){
                S = Math.max(S, stack.slice(-1) ^ A[i]);
                stack.pop();
            }
            if(stack.length > 0) S = Math.max(S, stack.slice(-1) ^ A[i]);
            stack.push(A[i])
        }
        return S;
    }