Skip to content

Instantly share code, notes, and snippets.

@jorgechato
Last active May 27, 2021 07:11
Show Gist options
  • Save jorgechato/aa0d223ccb5f000362cc3e72cb413e79 to your computer and use it in GitHub Desktop.
Save jorgechato/aa0d223ccb5f000362cc3e72cb413e79 to your computer and use it in GitHub Desktop.
Google

foobar.withgoogle.com

def solution(data, n):
"""
O(n^2)
"""
aux_dic = {}
for num in data:
aux_dic[num] = aux_dic.get(num, 0) + 1
to_remove = [num for num, times in aux_dic.items() if times > n]
return [num for num in data if num not in to_remove]
def solution(n, b):
circle_task_list = []
task_list = []
while True:
if n in circle_task_list:
return len(circle_task_list)
if n in task_list:
circle_task_list.append(n)
task_list.append(n)
n = get_task(n, b)
def to_base(n, b):
"""
Convert int to string with base b
"""
n_on_base = ""
while n > 0:
mod = n % b
n_on_base += str(mod)
n = n // b
return n_on_base
def get_task(n, b):
y = ''.join(sorted(n))
x = ''.join(sorted(n, reverse=True))
z = to_base(int(x, base=b) - int(y, base=b), b)
return '0'*(len(n)-len(z))+z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment