Sort by

recency

|

225 Discussions

|

  • + 0 comments

    This was my answer

    function getMaxLessThanK(n, k) {
        let max = 0;
        for (let i = 1; i < n; i++)
            for(let j = i + 1; j <= n; j++)
                if (max < (i & j) && (i & j) < k) {
                    max = (i & j);
                    if (max === k - 1) return max; // since it's the most expected value
                } 
        return max;
    }
    
  • + 0 comments

    function getMaxLessThanK(n,k){ let maxValue = 0; for(let i = 1; i

            let binaryAndValue = i & j;
            if(binaryAndValue >= k){
                break;
            }
            if(binaryAndValue > maxValue){
                maxValue = binaryAndValue;
            }
    
        }
    }
    return maxValue;
    

    }

  • + 0 comments
    function getMaxLessThanK(n, k) {
      let max = 0;
      let s = [];
    
    
        max = 0;
        for (let a = 1; a <= n; a++) {
          s.push(a);
          for (let b = a + 1; b <= n; b++) {
            let bit = a & b;
            if (bit < k && bit > max) {
              max = bit;
            }
          }
        }
      return max;
    }
    
  • + 0 comments
     if(n<k)return n-1;
        else if(n==2 || n==1 || n==0)
       return 0;
        return k-1;
    why this approach fails and give me some failure test cases
    
  • + 0 comments

    function getMaxLessThanK(n, k) {

    var out_max = 0;
    var out = 0;
    
    for (let i=1; i < n; i++) {
        for (let j=0; j < (n-i); j++) {
            out = i & (i+1)+j; // think of a=i and b=(i+1)+j
            if (out < k && out > out_max) {
                out_max = out;
            }
        }
    }
    return out_max;
    

    }