본문 바로가기

CodingTest

(61)
[연습] 코딩테스트 - 가사검색 코딩테스트 연습 programmers.co.kr 2020 KAKAO BLIND RECRUITMENT 가사검색 import re def solution(words, queries): answer = [] for query in queries: cnt = 0 for word in words: if re.findall(query.replace("?","."), word): if len(word) == len(query): cnt += 1 answer += [cnt] return answer 정확성, 효율성 5번은 통과되는데 효율성 1,2,3,4가 통과되지않는다. Trie라는 알고리즘을 써야한다고한다.
[연습] 코딩테스트 연습 - 크레인 인형뽑기 게임 코딩테스트 연습 programmers.co.kr 2019 카카오 개발자 겨울인턴십 문제 크레인 인형뽑기 게임 def solution(board, moves): block = {} for i in range(len(board[0])): tmp = [] for x in board[::-1]: if x[i] != 0: tmp += [x[i]] block[i+1] = tmp stack = [] answer = 0 for x in moves: if len(block[x]) == 0: continue catch = block[x].pop(-1) if len(stack) != 0 and stack[-1] == catch: stack.pop(-1) answer += 2 else: stack += [catch] retu..
[연습] 코딩테스트 연습 - 올바른괄호 코딩테스트 연습 programmers.co.kr 스킬체크 Level 2 올바른괄호 def solution(s): tmp = 0 for x in s: if x == "(": tmp += 1 else: tmp -=1 if tmp == -1: return False if tmp == 0: return True else: return False
[연습] 코딩테스트 연습 - 체육복 코딩테스트 연습 programmers.co.kr 스킬테스트 Level 1 체육복 def solution(n, lost, reserve): if len(lost) == 0: return n student = [1] * n for x in lost: student[x-1] -=1 for x in reserve: student[x-1] +=1 for x in range(len(student)): if student[x] == 0: try: if student[x-1] == 2 and x != 0: student[x] = 1 student[x-1] -=1 continue try: if student[x+1] ==2: student[x] =1 student[x+1] -=1 except: if student[x-1..
[연습] 코딩테스트 연습 - 땅따먹기 코딩테스트 연습 programmers.co.kr 스킬체크 Level 2 땅따먹기 def solution(land): f_land = [(i,v) for i, v in enumerate(land[0])] f_land = sorted(f_land, key = lambda x:x[1], reverse=True)[:2] answer =[] for x in range(len(land))[1:]: for i in range(len(land[x])): if f_land[0][0] != i: land[x][i]+= f_land[0][1] else: land[x][i] += f_land[1][1] answer = land[x] f_land = [(i,v) for i,v in enumerate(land[x])] f_lan..
[연습] 코딩테스트 (은행 데이터복구 문제) def solution(snap, trans): compre_snap = {x[0] : int(x[1]) for x in snap} re_trans = list(set([tuple(x) for x in trans])) for x in re_trans: # "ID", "DO", "ACCOUNT", "money" if x[2] in compre_snap.keys(): if x[1] == "SAVE": compre_snap[x[2]] += int(x[3]) elif x[1] == "WITHDRAW": compre_snap[x[2]] -= int(x[3]) else: compre_snap[x[2]] = int(x[3]) print(compre_snap) solution([["ACCOUNT1", "100"], [..
[연습] 코딩테스트 연습 (태그문제) def solution(data, tags): tmp = {x[0] : 0 for x in data} for x in tags: for y in data: if x in y: tmp[y[0]] +=1 tmp_sort = sorted(tmp.items(), key= lambda x: x[1], reverse=True) answer = [x[0] for x in tmp_sort if x[1] != 0] print(answer) solution([ ["doc1", "t1", "t2", "t3"], ["doc2", "t0", "t2", "t3"], ["doc3", "t1", "t6", "t7"], ["doc4", "t1", "t2", "t4"], ["doc5", "t6", "t100", "t8"], ], ["t..
[연습] 괄호문제 def solution(s): g_open= ["(","[","{",""] tmp = [] answer = 0 cnt = 0 for x in s: if x in g_open: tmp.append(x) try: if x in g_close: tmp.pop() answer +=1 except: return -1 if len(tmp) > 0: return -1 else: return answer print(solution(">_