-
순위 검색코딩 테스트/Level 2 2021. 4. 8. 20:55반응형
순위 검색
2021 KAKAO BLIND RECRUITMENT 1072명 완료programmers.co.kr/learn/courses/30/lessons/72412
일단 효율성을 신경쓰지 않고....
def solution(information, queries): answer = [] for query in queries: match = 0 for info in information: info_list = info.split() query_list = query.split() if query_list[0] == '-' or query_list[0] == info_list[0]: if query_list[2] == '-' or query_list[2] == info_list[1]: if query_list[4] == '-' or query_list[4] == info_list[2]: if query_list[6] == '-' or query_list[6] == info_list[3]: if query_list[7] == '-' or int(query_list[7]) <= int(info_list[4]): match += 1 answer.append(match) return answer
다음을 참고해서.....
tech.kakao.com/2021/01/25/2021-kakao-recruitment-round-1/
from bisect import insort, bisect_left def solution(information, queries): answer = [] group = {} for info in information: info_list = info.split() for lang in ('-', info_list[0]): for job in ('-', info_list[1]): for career in ('-', info_list[2]): for soul_food in ('-', info_list[3]): key = lang + job + career + soul_food group.setdefault(key, []) insort(group[key], int(info_list[4])) for query in queries: query_list = query.split() key = query_list[0] + query_list[2] + query_list[4] + query_list[6] if key in group: answer.append(len(group[key]) - bisect_left(group[key], int(query_list[7]))) else: answer.append(0) return answer
반응형