Skip to content

Instantly share code, notes, and snippets.

View onsmribah's full-sized avatar

Ons Mribah onsmribah

View GitHub Profile
from collections import Counter
def odd_occurences(elements):
"""returns the value of the unpaired element in odd number of elements.
:param elements: a list of integers.
:rtype: int
"""
odd_values = [value for value, count in Counter(A).iteritems() if count % 2 != 0]
# The task description assumes there should be one and only one odd value in the given list
def max_binary_gaps(n):
"""Finds the longest sequence of zeros in binary representation of an integer.
:param n: a given integer
:rtype: int
"""
gaps = "{0:b}".format(n).split('1')[1:-1]
return len(max(gaps)) if gaps else 0