bitwiseAnd.js

    0

    0

    The bitwiseAnd function takes two integers, N and K, and returns the bitmask of the two numbers as a number between 0 and 1. The function loops through the two integers, and for each integer, it calculates the bitwise AND of the integer with itself. If the result is less than or equal to K, then the max variable is set to the result. Otherwise, the max variable is left at the value of the result.

    function bitwiseAnd(N,K){
      let max = 0;
      for(let i = 1; i < N; i++){
        for(let j = i+1; j <= N; j++){
          let result = i & j;
          if(result < K && result > max){
            max = result;
          }
        }
      }
      return max;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.