• + 0 comments

    Java 8

    public static int bitwiseAnd(int N, int K) {
        // Write your code here
            int ret=0;
            for(int A=1;A<N;A++)
            {
                for(int B=A+1;B<=N;B++)
                {
                    if((A&B)<K)
                    {
                        ret=Math.max(ret, A&B);
                    }
                }
    
        }
        return ret;
    }