Sort by

recency

|

2806 Discussions

|

  • + 0 comments
    nb=bin(n)[2:]
    nb=nb.split('0')
    m=0    
    for i in nb:
        if len(i)>m:
            m=len(i)
    print(m)
            
    				
    				
    				
    				
    				
    				ANOTHER CODE
    				
    				
    				
    n=int(input())
    nb=bin(n)[2:]
    c,m=0,0
    for i in range(len(nb)):
        if nb[i]=='1':
            c+=1
            if c>m:
                m=c
        else:
            c=0
    print(m)
    
  • + 0 comments
    	
    int n = stoi(ltrim(rtrim(n_temp)));
        int counter{0};
        int maxCounter{0};
        
        while (n > 0) {
            
            if (n % 2 == 1)
                counter++;
            else {
                counter = 0;
            }
             
            n = round(n / 2);
    
            if (maxCounter < counter)
                maxCounter = counter;
        }
        
        cout << maxCounter << endl;
    
  • + 0 comments

    here's my c++ solution

        do {
            current = n & 1 ? current + 1 : 0;
            max = current > max ? current : max;
        } while (n >>= 1);
    
  • + 0 comments
    if __name__ == '__main__':
        n = int(input().strip())
        binary = f"{n:b}"
        pattern = r'1+'
        cons_occ = [len(i) for i in re.findall(pattern, binary)]
        print(max(cons_occ))
    
  • + 0 comments

    //JAVA

    int result=0; int temp=0; int n = Integer.parseInt(bufferedReader.readLine().trim()); for(int i=31; i>=0; i--){ int k = n>>i; if((k&1)>0){ temp++; result=Math.max(result, temp); }else { temp=0; }

        }
    

    System.out.println(result);