Last active
May 27, 2021 07:11
-
-
Save jorgechato/aa0d223ccb5f000362cc3e72cb413e79 to your computer and use it in GitHub Desktop.
Google
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 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] |
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 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