Sort by

recency

|

430 Discussions

|

  • + 0 comments

    in python -

    def bitwiseAnd(N, K): if K - 1 | K <= N: return K -1 else: return K-2

  • + 1 comment

    any one explain why this code works always int bitwiseAnd(int n, int k) { if (((k - 1) | k) <= n) { return k - 1; } else { return k - 2; } }

  • + 0 comments
    public static int bitwiseAnd(int N, int K) {
        return ((K - 1) | K) <= N ? K -1 : K -2;
    }
    
  • + 0 comments

    PYTHON 3 SOLUTION

    python:

        def bitwiseAnd(N, K):
            if K - 1 | K <= N:
                    return K -1
            return K-2
    
  • + 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;
    }