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
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 |
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 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 |