import numpy as np
def solution(m, n, board):
board_list = np.array([list(map(ord, x)) for x in board])
answer = 0
while True :
zero_list = set()
for h in range(m-1) :
for w in range(n-1) :
if board_list[h, w] == board_list[h, w+1] == board_list[h+1, w] == board_list[h+1, w+1] and board_list[h:h+2, w:w+2].sum() != -4:
zero_list.add((h, w))
zero_list.add((h, w+1))
zero_list.add((h+1, w))
zero_list.add((h+1, w+1))
for h, w in zero_list :
board_list[h, w] = -1
for w in range(n) :
for h in range(m) :
if board_list[h, w] == -1 :
tmp = board_list[:h,w].copy()
board_list[0,w] = -1
board_list[1:h+1,w] = tmp
if answer == len(board_list[board_list == -1]) :
return len(board_list[board_list == -1])
else :
answer = len(board_list[board_list == -1])
def solution(cacheSize, cities):
if cacheSize == 0 : return 5*len(cities)
cities = [x.lower() for x in cities]
LRU = []
cost = 0
for city in cities :
if city in LRU :
LRU.pop(LRU.index(city))
cost += 1
else :
if len(LRU) >= cacheSize:
LRU.pop(0)
cost += 5
LRU.append(city)
return cost
from collections import Counter
def solution(str1, str2) :
set1 = Counter(list(str1[i:i+2].upper() for i in range(len(str1) - 1) if str1[i:i+2].isalpha()))
set2 = Counter(list(str2[i:i+2].upper() for i in range(len(str2) - 1) if str2[i:i+2].isalpha()))
inter = set1 & set2
union = set1 | set2
return 65536 if len(union) == 0 else int((sum(inter.values()) / sum(union.values())) * 65536)
import numpy as np
def solution(arr1, arr2):
return np.dot(arr1, arr2).tolist()
from functools import reduce
def solution(n):
return reduce(lambda x, _ :[x[1], x[0] + x[1]], range(n-1), [0, 1])[1] % 1234567
from functools import reduce
def solution(A, B):
A.sort()
B.sort(reverse = True)
return reduce(lambda x, y : x + y[0]*y[1], zip(A, B), 0)
def solution(s):
arr = sorted(map(int, s.split(' ')))
return '{} {}'.format(arr[0], arr[-1])
def solution(s) :
stack = []
for alphabet in s :
if stack and stack[-1] == alphabet:
stack.pop()
else :
stack.append(alphabet)
return 1 * (not stack)
def solution(s) :
answer = [0, 0]
while s != '1' :
num_zeros = s.count('0')
s = bin(len(s) - num_zeros)[2:]
answer[0] += 1
answer[1] += num_zeros
return answer
def solution(n):
stack = [1]
answer = 0
sum_stack = 1
i = 2
while i <= n + 1:
if sum_stack == n:
answer += 1
sum_stack -= stack.pop(0)
if sum_stack < n:
stack.append(i)
sum_stack += i
i += 1
else:
sum_stack -= stack.pop(0)
return answer