• + 2 comments

    Those who are looking for javascript solution

    const n = parseInt(readLine(), 10);
        
        let count = 0;
        let result = 0;
        let arr = n.toString(2);
        for(let i = 0; i< arr.length; i++) {
            if(arr[i] == 0) {
                count = 0;
            } else {
                count++;
                result = Math.max(result, count)
            }
    
        }
        console.log(result)
    
    • + 1 comment

      thankyou so very much for this. i was working with list and everybody here provides a solution with a binary number in an integer variable. thanks alot for help.

      • + 0 comments

        glad i could

    • + 0 comments

      hi

      your solution is good but it can be optimize further. here is the trick to solve this problem in O(K).

      https://youtu.be/bc7cxeDy308