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 1 liner gives the correct result, but creates a non satisfactory intermediary list:
"11001".split('0') returns ['11', '', '1']
However, the desired list is the list of all 1s and should be ['11', '1']
we need to split with 1 or more consecutive 0s:
re.split("0+", "11001") returns ['11', '1']
which is a better list (you could use it to answer questions like: how many blocs of consecutive 1s are there in the binary representation?)
the one liner becomes:
print(len(max(re.split("0+",bin(int(input().strip()))[2:]))))
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 1 liner gives the correct result, but creates a non satisfactory intermediary list:
"11001".split('0') returns ['11', '', '1']
However, the desired list is the list of all 1s and should be ['11', '1']
we need to split with 1 or more consecutive 0s:
re.split("0+", "11001") returns ['11', '1']
which is a better list (you could use it to answer questions like: how many blocs of consecutive 1s are there in the binary representation?)
the one liner becomes:
print(len(max(re.split("0+",bin(int(input().strip()))[2:]))))