Monday, March 14, 2022

Hacker Rank 30 day code challenge Python

 Problem:

Convert a number 'n' to its binary base 2. Find base 10 integers 0,1. Find max number of consecutive 1's.

import math

no = int(input())
arr = []
while no // 2 > 0:
remainder = no % 2
arr.append(remainder)
no = no // 2

arr.append(no)
max = []

count = 0
for i in arr:

if i == 1:
count = count + 1
max.append(count)
else:
count = 0

max.sort()

print(max[-1]) 

No comments:

Post a Comment