30 days of code: Day 10

https://www.hackerrank.com/challenges/30-binary-numbers/

To be honest, I looked this one up. In fact, many people had the same solution. Don’t really know who the original is, but thanks. Decided not to write the Task, head to link above for full details on the problem.

var n = int.Parse(Console.ReadLine());

var sum = 0;
var max = 0;


while (n > 0)
{
    if (n % 2 == 1)
    {
        sum++;

        if (sum > max)
            max = sum;
    }
    else sum = 0;

    n = n / 2;
}

Console.WriteLine(max);

Leave a Reply

Your email address will not be published. Required fields are marked *