Skip to content

Instantly share code, notes, and snippets.

@rafaltrojanowski
Last active November 26, 2017 09:27
Show Gist options
  • Save rafaltrojanowski/b265e01ada0e143a2cab93489daaa486 to your computer and use it in GitHub Desktop.
Save rafaltrojanowski/b265e01ada0e143a2cab93489daaa486 to your computer and use it in GitHub Desktop.
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