Sort by

recency

|

2807 Discussions

|

  • + 0 comments
    import re
    print(len(max(re.findall(r"(1+)",bin(int(input().strip()))[2:]))))
    
  • + 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))