Sort by

recency

|

431 Discussions

|

  • + 0 comments

    def bitwiseAnd(N, K): max_and = 0 for b in range(2, N + 1): for a in range(1, b): current_and = a & b if max_and < current_and < K: max_and = current_and # Optimization: if we hit K-1, we found the highest possible value if max_and == K - 1: return max_and return max_and

  • + 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