We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. LinkedIn Placements
  4. Consecutive 1's in Binary Numbers
  5. Discussions

Consecutive 1's in Binary Numbers

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 81 Discussions, By:

recency

Please Login in order to post a comment

  • allick
    9 months ago+ 0 comments

    python3

    n = int(input())
    s = str(bin(n))
    l = []
    ss = 0
    for i in s:
        if i == '1':
            ss += 1
            l.append(ss)
        elif i == '0':
            ss = 0
    print(max(l))
    
    0|
    Permalink
  • Kanahaiya
    3 years ago+ 0 comments

    hi

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

    https://youtu.be/bc7cxeDy308

    0|
    Permalink
  • mukunda05holla
    4 years ago+ 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)
    
    0|
    Permalink
  • priti_jha
    4 years ago+ 1 comment

    Stack stack=new Stack(); int count=1,i=-1,max=0; while(n!=0) { stack.push(n%2); n=n/2; } while(!stack.isEmpty()) { if(stack.peek()==i) { count++; }

            if(max<count)
            {
                max=count;
            }
            i=stack.peek();
    
            if(i==0)
            {
                count=1;
            }
            stack.pop();
        }
    
    0|
    Permalink
  • bob_crosby5123
    4 years ago+ 0 comments

    When we state real estate logos design, we mean a brand mark which has a capacity to impart in the interest of their business to the world. It's anything but a medium-term work for it requires a broad research work about the most recent real estate logo design patterns and contender's image imprint to think of something that is one of a kind, captivating and eye-getting.

    0|
    Permalink
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy