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.
It reads the number, checks if it's divisible by 2 since we only have two possiblities 0 or 1, the reminder will be 1 for 1/2 and 0 for 0/2, so since we're counting the max consecutives of '1', the counter is adding itself + 1 every consecutive appeareance of '1', when 0 appears the reminder is 0, and any number * 0 = 0, so that resets the counter, at the end we only save the maxCounter and print the value of the maxCounter. I hope it helps you to understand the code.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 10: Binary Numbers
You are viewing a single comment's thread. Return to all comments →
It reads the number, checks if it's divisible by 2 since we only have two possiblities 0 or 1, the reminder will be 1 for 1/2 and 0 for 0/2, so since we're counting the max consecutives of '1', the counter is adding itself + 1 every consecutive appeareance of '1', when 0 appears the reminder is 0, and any number * 0 = 0, so that resets the counter, at the end we only save the maxCounter and print the value of the maxCounter. I hope it helps you to understand the code.