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.
The variable max holds the largest number of ones in a row so far. For example, if n is 11101111, after four loops max will equal 4 for the four ones that are in a row. counter will reset to 0 at the 0 in n and count up to 3 for the three ones in a row but 3 is less than 4 so after eight loops Math.max() will set max to whichever is more, max which is 4 in this example or counter which is only 3.
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 →
The variable max holds the largest number of ones in a row so far. For example, if n is 11101111, after four loops max will equal 4 for the four ones that are in a row. counter will reset to 0 at the 0 in n and count up to 3 for the three ones in a row but 3 is less than 4 so after eight loops Math.max() will set max to whichever is more, max which is 4 in this example or counter which is only 3.