Sort by

recency

|

2811 Discussions

|

  • + 0 comments

    JS

    function main() {
        const n = parseInt(readLine().trim(), 10);
        const b = n.toString(2);
        const myArray = b.split('0').map((x) => x.length);
        console.log(Math.max(...myArray));
    }
    
  • + 0 comments

    code in pyhton3

    binary_str = bin(n)[2:]
    
    target_no = "1"
    current_count = 0
    max_count = 0
    
    for x in binary_str:
        if x == target_no:
            current_count += 1
            if current_count>max_count:
                max_count = current_count
            else:
                max_count
        else:
            current_count = 0
    print(max_count)
    
  • + 0 comments

    Java

    public class Solution {
        public static void main(String[] args) throws IOException {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    
            int n = Integer.parseInt(bufferedReader.readLine().trim());
       
            int max = 0; 
            int count = 0;
    
        ArrayList <Integer> binary = new ArrayList<>();
        while (n>0) {
            int remainder = n%2;
            n=n/2;
            binary.add(remainder);
        }
       for(int i = 0; i<binary.size();i++)
       {
           int position = binary.get(i);
           if(position == 1)
           {
               count++;
                 max = Math.max(count, max);
           }
           else
           {           
             count = 0;  
           } 
       }      
       System.out.println(max);
       
            bufferedReader.close();
        }
    }
    
  • + 0 comments

    C#

        int n = Convert.ToInt32(Console.ReadLine().Trim());
        int count = 0;
        int max = 0;
    
        var bin = Convert.ToString(n, 2);
    
        for(int number = 0; number < bin.Length; number++)
        {
            if(bin[number] == '1')
            {
                count++;
            }
            else
            {
                count = 0;
            }
    
            if(count > max) max = count;
        }
    
        Console.WriteLine(max);
    
  • + 0 comments
    import re
    print(len(max(re.findall(r"(1+)",bin(int(input().strip()))[2:]))))