We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 29: Bitwise AND
  5. Discussions

Day 29: Bitwise AND

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 386 Discussions, By:

recency

Please Login in order to post a comment

  • ranieri_michel
    2 days ago+ 0 comments

    C# Solution:

      public static int bitwiseAnd(int N, int K)
      {
        int max = 0;
        int compare = 0;
        for(int i = 1; i<N; i++)
          for(int j = i+1; j<=N; j++)
          {
            compare = i&j;
            max = max < compare && compare < K ? compare : max;
          }
        return max;
      }
    
    0|
    Permalink
  • fran_mahon
    3 weeks ago+ 1 comment

    Python

    def bitwiseAnd(N, K):
        max_val = 0
        for i in range(K-2,N):
            for j in range(i+1,N+1):
                val = i&j
                if val == K-1:
                    return val
                if max_val<val<K:
                    max_val = val
        return max_val
    
    0|
    Permalink
  • pandit_manish
    1 month ago+ 0 comments
    public static int bitwiseAnd(int N, int K) {
            int max = Integer.MIN_VALUE;
            for(int i=1;i<=N;i++){
                for(int j=i+1;j<=N;j++){
                    int result = i&j;
                    if(result < K && result > max) {
                        max = result;
                    }
                }
            }
            return max;
        }
    
    0|
    Permalink
  • denkanono
    2 months ago+ 0 comments

    JavaScript Solution

    function bitwiseAnd(N, K) {
        let max = 0;
        
        for(let i = 1; i <= N; i++) {
            for(let j = N; j > i; j--) {
                let bitAndOp = i & j;
                if(bitAndOp > max && bitAndOp < K ) {
                    max = bitAndOp;
                }
            }
        }
        
        return max;
    }
    
    0|
    Permalink
  • jani_lazar13
    2 months ago+ 0 comments

    Hi, is programmer forced to use the bitwise & operator in the solution code? My solution lacks the concrete use of the operator, but it works based on the features of how it operates on its operands. Shall I use literally the operator in my solution to get passed all test cases?

    0|
    Permalink
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy