Last active
November 26, 2017 09:27
-
-
Save rafaltrojanowski/b265e01ada0e143a2cab93489daaa486 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(n) | |
binary_array = to_binary(n) | |
i = 0 | |
j = 0 | |
max = 0 | |
counter = 0 | |
while i < binary_array.size - 1 | |
counter = 0 | |
if binary_array[i] == 1 && binary_array[i+1] == 0 | |
j = i + 1 | |
while binary_array[j] == 0 | |
counter += 1 | |
j += 1 | |
end | |
if counter > max | |
max = counter | |
end | |
end | |
i += 1 | |
end | |
max | |
end | |
def to_binary(n) | |
arr = [] | |
while n > 0 | |
i = n % 2 | |
arr << i | |
n = n / 2 | |
end | |
arr | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment