• + 0 comments

    This was my answer

    function getMaxLessThanK(n, k) {
        let max = 0;
        for (let i = 1; i < n; i++)
            for(let j = i + 1; j <= n; j++)
                if (max < (i & j) && (i & j) < k) {
                    max = (i & j);
                    if (max === k - 1) return max; // since it's the most expected value
                } 
        return max;
    }