1. 백준 - 숨바꼭질 3
from collections import deque
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
lst = [0] * 100001
Q = deque()
Q.append(N)
while Q:
s = Q.popleft()
if s == K:
print(lst[s])
break
for i in (s*2, s-1, s+1):
if 0 <= i <= 100000 and not lst[i]:
if i == s*2:
lst[i] = lst[s]
else:
lst[i] = lst[s] + 1
Q.append(i)
2. 프로그래머스 - 영어 끝말잇기
def solution(n, words):
answer = 1
end = 0
check = { i : 0 for i in set(words)}
check[words[0]] = 1
if len(words[0]) == 1:
return [1, 1]
for i in range(1, len(words)):
answer += 1
if words[i-1][-1] != words[i][0]:
end = 1
break
elif len(words[i]) == 1:
end = 1
break
elif check[words[i]] == 1:
end = 1
break
else:
check[words[i]] = 1
if answer == len(words) and end == 0:
return [0, 0]
return [answer % n if answer % n != 0 else n, answer // n if answer % n == 0 else answer // n + 1]