def solution(participant, completion):
answer = ''
dict = {}
sum = 0
for part in participant:
print(hash(part))
dict[hash(part)] = part
sum += hash(part)
for comp in completion:
sum -= hash(comp)
return dict[sum]
def solution(phone_book):
dict = {}
for num in phone_book:
dict[num] = 1
for num in phone_book:
a = ""
for n in num:
a += n
if a in dict and a != num:
return False
return True
def solution(clothes):
hash_map = {}
for clothe, type in clothes:
hash_map[type] = hash_map.get(type, 0) + 1
answer = 1
for type in hash_map:
answer *= (hash_map[type] + 1)
return answer - 1
import math
def solution(progresses, speeds):
answer = []
days = [math.ceil((100-p)/s) for p, s in zip(progresses, speeds)]
idx = 0
for i in range(len(days)):
if days[idx] < days [i]:
answer.append(i-idx)
idx = i
answer.append(len(days) - idx)
return answer
def solution(priorities, location):
queue = [(i,p) for i,p in enumerate(priorities)]
print(queue)
answer = 0
while True:
cur = queue.pop(0)
if any(cur[1] < q[1] for q in queue):
queue.append(cur)
else:
answer += 1
if cur[0] == location:
return answer
def solution(answers):
list1 = [1, 2, 3, 4, 5]
list2 = [2, 1, 2, 3, 2, 4, 2, 5]
list3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
score = [0,0,0]
answer = []
for a in range(len(answers)):
if list1[a%len(list1)]==answers[a]:
score[0] += 1
if list2[a%len(list2)]==answers[a]:
score[1] += 1
if list3[a%len(list3)]==answers[a]:
score[2] += 1
for i, s in enumerate(score):
if s == max(score):
answer.append(i+1)
return answer
def solution(brown, yellow):
answer = []
total = brown + yellow
for b in range(1,total+1):
if (total / b) % 1 == 0:
a = total / b
if a >= b:
if (a-2)*(b-2) == yellow:
return [a,b]
return answer
def solution(numbers, target):
answer = 0
queue = [[numbers[0],0], [-1*numbers[0],0]]
n = len(numbers)
while queue:
print(queue)
temp, idx = queue.pop()
print(temp, idx)
idx += 1
if idx < n:
queue.append([temp+numbers[idx], idx])
queue.append([temp-numbers[idx], idx])
else:
if temp == target:
answer += 1
print(queue)
return answer