Skip to content

Instantly share code, notes, and snippets.

View Ronnasayd's full-sized avatar
👽
Working

Ronnasayd Ronnasayd

👽
Working
View GitHub Profile
@fmasanori
fmasanori / facebook_hackaton.py
Last active September 27, 2017 16:59
Selection Test 2013 Facebook Hackaton Given two positive integers n and k, generate all binary integer between 0 and 2 ** n-1, inclusive. These binaries will be drawn in descending order according to the number of existing 1s. If there is a tie choose the lowest numerical value. Return the k-th element from the selected list. Eg n = 3 and k = 5 …
def hack1(n, k):
def f(s):
return s.count('1')
binaries = []
for x in range(2**n):
binaries.append(bin(x))
binaries.sort(key=f, reverse = True)
return binaries[k - 1]
def hack(n, k):