A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N.
For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The number 529 has binary representation 1000010001 and contains two binary gaps: one of length 4 and one of length 3. The number 20 has binary representation 10100 and contains one binary gap of length 1. The number 15 has binary representation 1111 and has no binary gaps. The number 32 has binary representation 100000 and has no binary gaps.
Write a function:
def solution(N)
that, given a positive integer N, returns the length of its longest binary gap. The function should return 0 if N doesn't contain a binary gap.
For example, given N = 1041 the function should return 5, because N has binary representation 10000010001 and so its longest binary gap is of length 5. Given N = 32 the function should return 0, because N has binary representation '100000' and thus no binary gaps.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..2,147,483,647].
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'NoneType'> found.
Invalid result type, int expected, <class 'NoneType'> found.
Invalid result type, int expected, <class 'NoneType'> found.
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'NoneType'> found.stdout:
0b10000010001
Invalid result type, int expected, <class 'NoneType'> found.stdout:
0b1111
Invalid result type, int expected, <class 'NoneType'> found.stdout:
0b100000
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'NoneType'> found.stdout:
10000010001
Invalid result type, int expected, <class 'NoneType'> found.stdout:
1111
Invalid result type, int expected, <class 'NoneType'> found.stdout:
100000
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
if mask ==1 and i =='0':
count += count
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer =count
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer =count
return answer
10000010001
1111
Traceback (most recent call last): File "exec.py", line 109, in <module> main() File "exec.py", line 85, in main result = solution( N ) File "/tmp/exec_user_kos3ivag/solution.py", line 19, in solution return answer UnboundLocalError: local variable 'answer' referenced before assignmentstdout:
100000
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer =count
print(answer)
return answer
10000010001 0
1111 0
Traceback (most recent call last): File "exec.py", line 109, in <module> main() File "exec.py", line 85, in main result = solution( N ) File "/tmp/exec_user_99ub3cxb/solution.py", line 19, in solution print(answer) UnboundLocalError: local variable 'answer' referenced before assignmentstdout:
100000
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
ans
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer =count
print(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = 0
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer =count
print(answer)
return answer
10000010001 0
1111 0
100000 0
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = 0
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer = count
print(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer = count
print(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer.append(count)
print(answer)
return answer
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'list'> found.stdout:
10000010001 [0]
Invalid result type, int expected, <class 'list'> found.stdout:
1111 [0, 0]
Invalid result type, int expected, <class 'list'> found.stdout:
100000 []
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer.append(count)
print(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
count += count
elif i =='1' and mask == 1:
mask = 0
#binary gap end
answer.append(count)
print(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif mask ==1 and i =='0':
print("This i is here!" + str(i))
count += count
elif i =='1' and mask == 1:
print("MAsk over" + str(i))
mask = 0
#binary gap end
answer.append(count)
print(answer)
return answer
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'list'> found.stdout:
10000010001 1 This i is here.1 0 This i is here!0 0 This i is here!0 0 This i is here!0 0 This i is here!0 0 This i is here!0 1 MAsk over1 0 0 0 1 This i is here.1 [0]
Invalid result type, int expected, <class 'list'> found.stdout:
1111 1 This i is here.1 1 MAsk over1 1 This i is here.1 1 MAsk over1 [0, 0]
Invalid result type, int expected, <class 'list'> found.stdout:
100000 1 This i is here.1 0 This i is here!0 0 This i is here!0 0 This i is here!0 0 This i is here!0 0 This i is here!0 []
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0':
print("This i is here!" + str(i))
count += count
elif i =='1' and mask == 1:
print("MAsk over" + str(i))
mask = 0
#binary gap end
answer.append(count)
print(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
print("This i is here!" + str(i))
count += count
elif i =='1' and mask == 1:
print("MAsk over" + str(i))
mask = 0
#binary gap end
answer.append(count)
print(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
print("This i is here!" + str(i))
count += count
print(count)
elif i =='1' and mask == 1:
print("MAsk over" + str(i))
mask = 0
#binary gap end
answer.append(count)
print(answer)
return answer
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'list'> found.stdout:
10000010001 1 This i is here.1 0 This i is here!0 0 0 This i is here!0 0 0 This i is here!0 0 0 This i is here!0 0 0 This i is here!0 0 1 MAsk over1 0 0 0 1 This i is here.1 [0]
Invalid result type, int expected, <class 'list'> found.stdout:
1111 1 This i is here.1 1 MAsk over1 1 This i is here.1 1 MAsk over1 [0, 0]
Invalid result type, int expected, <class 'list'> found.stdout:
100000 1 This i is here.1 0 This i is here!0 0 0 This i is here!0 0 0 This i is here!0 0 0 This i is here!0 0 0 This i is here!0 0 []
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
print("This i is here!" + str(i))
count += 1
print(count)
elif i =='1' and mask == 1:
print("MAsk over" + str(i))
mask = 0
#binary gap end
answer.append(count)
print(answer)
return answer
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'list'> found.stdout:
10000010001 1 This i is here.1 0 This i is here!0 1 0 This i is here!0 2 0 This i is here!0 3 0 This i is here!0 4 0 This i is here!0 5 1 MAsk over1 0 0 0 1 This i is here.1 [5]
Invalid result type, int expected, <class 'list'> found.stdout:
1111 1 This i is here.1 1 MAsk over1 1 This i is here.1 1 MAsk over1 [0, 0]
Invalid result type, int expected, <class 'list'> found.stdout:
100000 1 This i is here.1 0 This i is here!0 1 0 This i is here!0 2 0 This i is here!0 3 0 This i is here!0 4 0 This i is here!0 5 []
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
print("This i is here!" + str(i))
count += 1
print(count)
elif i =='1' and mask == 1:
print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
print(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
print("This i is here!" + str(i))
count += 1
print(count)
elif i =='1' and mask == 1:
print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = []
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
print("This i is here!" + str(i))
count += 1
print(count)
elif i =='1' and mask == 1:
print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
10000010001 1 This i is here.1 0 This i is here!0 1 0 This i is here!0 2 0 This i is here!0 3 0 This i is here!0 4 0 This i is here!0 5 1 MASK over1 0 0 0 1 This i is here.1
1111 1 This i is here.1 1 MASK over1 1 This i is here.1 1 MASK over1
Traceback (most recent call last): File "exec.py", line 109, in <module> main() File "exec.py", line 85, in main result = solution( N ) File "/tmp/exec_user_cp0vgoip/solution.py", line 26, in solution answer = max(answer) ValueError: max() arg is an empty sequencestdout:
100000 1 This i is here.1 0 This i is here!0 1 0 This i is here!0 2 0 This i is here!0 3 0 This i is here!0 4 0 This i is here!0 5
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
print("This i is here!" + str(i))
count += 1
print(count)
elif i =='1' and mask == 1:
print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
10000010001 1 This i is here.1 0 This i is here!0 1 0 This i is here!0 2 0 This i is here!0 3 0 This i is here!0 4 0 This i is here!0 5 1 MASK over1 0 0 0 1 This i is here.1
1111 1 This i is here.1 1 MASK over1 1 This i is here.1 1 MASK over1
100000 1 This i is here.1 0 This i is here!0 1 0 This i is here!0 2 0 This i is here!0 3 0 This i is here!0 4 0 This i is here!0 5
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
print(i)
if i == '1' and mask == 0:
print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
10000010001 This i is here!0 This i is here!0 This i is here!0 This i is here!0 This i is here!0
1111
100000 This i is here!0 This i is here!0 This i is here!0 This i is here!0 This i is here!0
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
10000010001
1111
100000
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
mask = 1
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def found(new_bin, )
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def found(new_bin, answer):
for i in new_bin:
if i ==
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def found(new_bin, answer):
count = 0
mask = 0
for i in new_bin:
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
return answer
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def found(new_bin, answer):
count = 0
mask = 0
for i in new_bin:
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
return answer
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def found(new_bin, answer):
count = 0
mask = 0
for i in new_bin:
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
return answer
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
print(binNun[i:])
answer = max(answer)
return answer
example test n=1041=10000010001_2
tested program terminated with exit code 1
Traceback (most recent call last): File "exec.py", line 109, in <module> main() File "exec.py", line 85, in main result = solution( N ) File "/tmp/exec_user_sr9m_6eo/solution.py", line 46, in solution print(binNun[i:]) NameError: name 'binNun' is not defined
Traceback (most recent call last): File "exec.py", line 109, in <module> main() File "exec.py", line 85, in main result = solution( N ) File "/tmp/exec_user_sr9m_6eo/solution.py", line 46, in solution print(binNun[i:]) NameError: name 'binNun' is not defined
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def found(new_bin, answer):
count = 0
mask = 0
for i in new_bin:
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
return answer
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N).split("b")[-1]
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N)
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N)
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N)
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
[81]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N)
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
[81]
[3]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(N):
binNum = bin(N)
#print(binNum)
mask = 0
count = 0
answer = [0]
for i in binNum :
#print(i)
if i == '1' and mask == 0:
#print("This i is here." + str(i))
mask = 1
#bninary gap start 존재
elif i =='0'and mask ==1 :
#print("This i is here!" + str(i))
count += 1
#print(count)
elif i =='1' and mask == 1:
#print("MASK over" + str(i))
mask = 0
#binary gap end
answer.append(count)
answer = max(answer)
return answer
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
for i in range(0, len(binNum)):
if binNum[i] == '1':
one_idx.append(i)
print(i)
answer = 1
return answer
[81]
12
5
7
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
for i in range(0, len(binNum)):
if binNum[i] == '1':
one_idx.append(i)
print(one_idx)
answer = 1
return answer
[81]
[2, 8, 12]
[2, 3, 4, 5]
[2]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
for i in range(0, len(binNum)):
if binNum[i] == '1':
one_idx.append(i)
print(one_idx)
[81]
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'NoneType'> found.stdout:
[2, 8, 12]
Invalid result type, int expected, <class 'NoneType'> found.stdout:
[2, 3, 4, 5]
Invalid result type, int expected, <class 'NoneType'> found.stdout:
[2]
Invalid result type, int expected, <class 'NoneType'> found.stdout:
[2, 4, 8]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
for i in range(0, len(binNum)):
if binNum[i] == "1":
print(binNum[i])
one_idx.append(i)
print(one_idx)
[81]
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'NoneType'> found.stdout:
1 1 1 [2, 8, 12]
Invalid result type, int expected, <class 'NoneType'> found.stdout:
1 1 1 1 [2, 3, 4, 5]
Invalid result type, int expected, <class 'NoneType'> found.stdout:
1 [2]
Invalid result type, int expected, <class 'NoneType'> found.stdout:
1 1 1 [2, 4, 8]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
return 0
[81]
example test n=1041=10000010001_2
tested program terminated with exit code 1
Invalid result type, int expected, <class 'NoneType'> found.
Invalid result type, int expected, <class 'NoneType'> found.
Invalid result type, int expected, <class 'NoneType'> found.
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(0, len(one_idx)):
answer = max()
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(0, len(one_idx)):
max_dist = max(max_dist, )
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(0, len(one_idx)):
max_dist = max(max_dist, one_idx[i+1] - one_idx[i] +1)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
max_dist = 0
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(0, len(one_idx)):
max_dist = max(max_dist, one_idx[i+1] - one_idx[i] +1)
return max_dist
[81]
example test n=1041=10000010001_2
tested program terminated with exit code 1
Traceback (most recent call last): File "exec.py", line 109, in <module> main() File "exec.py", line 85, in main result = solution( N ) File "/tmp/exec_user_1ovnyzmq/solution.py", line 20, in solution max_dist = max(max_dist, one_idx[i+1] - one_idx[i] +1) IndexError: list index out of range
Traceback (most recent call last): File "exec.py", line 109, in <module> main() File "exec.py", line 85, in main result = solution( N ) File "/tmp/exec_user_1ovnyzmq/solution.py", line 20, in solution max_dist = max(max_dist, one_idx[i+1] - one_idx[i] +1) IndexError: list index out of range
Traceback (most recent call last): File "exec.py", line 109, in <module> main() File "exec.py", line 85, in main result = solution( N ) File "/tmp/exec_user_1ovnyzmq/solution.py", line 20, in solution max_dist = max(max_dist, one_idx[i+1] - one_idx[i] +1) IndexError: list index out of range
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
max_dist = 0
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(1, len(one_idx)):
max_dist = max(max_dist, one_idx[i+1] - one_idx[i] +1)
return max_dist
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
max_dist = 0
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(1, len(one_idx)):
max_dist = max(max_dist, one_idx[i] - one_idx[i-1] +1)
return max_dist
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
max_dist = 0
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(1, len(one_idx)):
max_dist = max(max_dist, one_idx[i] - one_idx[i-1] +1)
return max_dist
[81]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
max_dist = 0
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(1, len(one_idx)):
max_dist = max(max_dist, one_idx[i] - one_idx[i-1] -1)
return max_dist
[81]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
max_dist = 0
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(1, len(one_idx)):
max_dist = max(max_dist, one_idx[i] - one_idx[i-1] -1)
return max_dist
[81]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 81 = 1010001
def solution(N):
binNum = bin(N)
one_idx = []
max_dist = 0
for i in range(0, len(binNum)):
if binNum[i] == "1":
one_idx.append(i)
if len(one_idx) <= 1:
# binary gap의 조건이 만족되지 않았으면 바로 0 return
return 0
for i in range(1, len(one_idx)):
max_dist = max(max_dist, one_idx[i] - one_idx[i-1] -1)
return max_dist
The solution obtained perfect score.