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.
wow. there was another one on here that needed a list comprehension to do this. Your answer is cleaner and simpler. I did not think of this combo and did it with loops and counters:
importsysn=int(input().strip())tst=str(bin(n))tst=tst[2:]ones=0maxOnes=0foriintst:ifi=='1':ones+=1ifmaxOnes<ones:maxOnes=oneselse:ones=0# reset ones when 0 encounteredprint(maxOnes)
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 →
wow. there was another one on here that needed a list comprehension to do this. Your answer is cleaner and simpler. I did not think of this combo and did it with loops and counters: