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.
Since I was having problems in Python 3 getting all the test cases, I tried yours:
remainder=0
sumVal=0
total=0
while(n>0):
remainder=n%2;
n=n/2;
if(remainder==1):
sumVal += 1
if(sumVal>=total):
total=sumVal;
else:
sumVal=0
print(total)
Just wouldn't work. Would appreciate some advice. Thanks in anticipation.
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 →
Since I was having problems in Python 3 getting all the test cases, I tried yours: remainder=0 sumVal=0 total=0 while(n>0): remainder=n%2; n=n/2; if(remainder==1): sumVal += 1 if(sumVal>=total):
total=sumVal; else: sumVal=0 print(total)