• + 0 comments

    In C#

        public static int bitwiseAnd(int N, int K)
        {
            int maxVal = 0;
            
            for(int a = 1; a < N; a++)
            {
                for(int b = a + 1; b <= N; b++)
                {
                    int ab = a & b;
                    if(ab < K && ab > maxVal)
                        maxVal = ab;
                }
            }
            
            return maxVal;
        }