• + 0 comments

    JavaScript/TypeScript

    function bitwiseAnd(N: number, K: number): number {
        let max = 0;
        let aANDb;
    
        for (let a = 1; a < N; a++) {
            for (let b = a + 1; b <= N; b++) {
                aANDb = a & b;
                if ((aANDb) < K && (aANDb) > max) {
                    max = aANDb;
                }
            }
        }
    
        return max;
    }