Skip to content

Instantly share code, notes, and snippets.

@stephen-maina
Created August 24, 2018 08:35
Show Gist options
  • Save stephen-maina/319e0059c797e449ca4db1c8c56ba4f3 to your computer and use it in GitHub Desktop.
Save stephen-maina/319e0059c797e449ca4db1c8c56ba4f3 to your computer and use it in GitHub Desktop.
Codility Lesson 1
def solution(N):
# write your code in Python 3.6
binaryNumber=bin(N);
binaryGap=0;
data=str(binaryNumber);
finalList=[];
dataList=[];
#print(data);
for index in range(len(data)):
if(data[index]=="1" and "1" in dataList and "0" in dataList):
#print(dataList);
dataList.append(data[index]);
#print(dataList);
finalList.append(dataList);
#print(finalList);
dataList=[];
#print(dataList);
dataList.append(data[index]);
#print(dataList);
elif (data[index]=="1"and "1" in dataList and "0" not in dataList):
dataList=[];
dataList.append(data[index]);
elif (data[index]=="0"and "1" not in dataList):
dataList=[];
elif (data[index]!="0"and data[index]!="1"):
dataList=[];
else:
dataList.append(data[index]);
maxLength=0;
for index in range(len(finalList)):
#print(maxLength);
#print(len(finalList[index]));
if(maxLength<len(finalList[index])-2):
maxLength=len(finalList[index])-2;
return maxLength;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment