Sort by

recency

|

429 Discussions

|

  • + 0 comments

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

    the max value before k will be k-1 is it exists print k-1 else k-2 the next largest value before k-1