Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 추천시스템
- 삼성SDS Brightics
- 브라이틱스
- 팀 분석
- 삼성 SDS
- 삼성 SDS Brigthics
- 삼성SDS Brigthics
- 영상제작기
- 모델링
- 혼공머신
- 혼공머신러닝딥러닝
- 직원 이직률
- Brightics Studio
- Brigthics
- 혼공학습단
- Brigthics Studio
- Brightics를 이용한 분석
- 직원 이직여부
- 데이터분석
- 노코드AI
- Brightics
- 삼성SDS
- 포스코 아카데미
- 캐글
- 개인 의료비 예측
- 혼공
- Brigthics를 이용한 분석
- 브라이틱스 서포터즈
- 데이터 분석
- 포스코 청년
Archives
- Today
- Total
데이터사이언스 기록기📚
[프로그래머스/Python] Level 2_순위 검색 (2021 KAKAO BLIND RECRUITMENT) 본문
Coding Test/프로그래머스(Python)
[프로그래머스/Python] Level 2_순위 검색 (2021 KAKAO BLIND RECRUITMENT)
syunze 2023. 11. 12. 21:35📌문제 유형
2021 KAKAO BLIND RECRUITMENT
📌문제
📌나의 문제풀이
- 정확성 통과, 효율성 4문제 오답
import re
def solution(info, query):
answer = []
# info 나누기
new_info = []
info_scores = []
for line in info:
tmp = list(map(str,line.split(' ')))
new_info.append(tmp[:-1])
info_scores.append(int(tmp[-1]))
# query 나누기
querys = []
q_scores = []
for q in query:
t = re.split(' and | ',q)
q_scores.append(int(t[-1]))
querys.append(t[:-1])
for i in range(len(querys)):
result = 0
for j in range(len(new_info)):
# 점수가 맞는 경우만 조건 따지기
if q_scores[i] <= info_scores[j]:
if querys[i] == new_info[j] and querys[i] == ['-' ,'-', '-', '-']:
result += 1
else:
flag = 0
for k in range(len(querys[i])):
if querys[i][k] == '-':
continue
elif querys[i][k] != new_info[j][k]:
flag = 1
break
else:
continue
if flag == 0:
result += 1
answer.append(result)
return answer
📌다른 사람들의 풀이
from itertools import combinations
from collections import defaultdict
from bisect import bisect_left
def solution(information, queries):
answer = []
dic = defaultdict(list)
for info in information:
info = info.split()
condition = info[:-1]
score = int(info[-1])
for i in range(5):
case = list(combinations([0,1,2,3], i))
for c in case:
tmp = condition.copy()
for idx in c:
tmp[idx] = "-"
key = ''.join(tmp)
dic[key].append(score)
for value in dic.values():
value.sort()
for query in queries:
query = query.replace("and ", "")
query = query.split()
target_key = ''.join(query[:-1])
target_score = int(query[-1])
count = 0
if target_key in dic:
target_list = dic[target_key]
idx = bisect_left(target_list, target_score)
count = len(target_list) - idx
answer.append(count)
return answer
📌리뷰
- 이분탐색 문제. 생각보다 변수 수가 적으면 dic 활용도 생각해보기
- Python 이분탐색은 bisect 활용
728x90
'Coding Test > 프로그래머스(Python)' 카테고리의 다른 글
[프로그래머스/Python] Level 3_단어 변환(DFS) (0) | 2023.11.16 |
---|---|
[프로그래머스/Python] Level 3_네트워크(BFS) (0) | 2023.11.15 |
[프로그래머스/Python] Level 2_k진수에서 소수 개수 구하기 (2022 KAKAO BLIND RECRUITMENT) (0) | 2023.11.12 |
[프로그래머스/Python] Level 2_거리두기 확인하기 (2021 카카오 채용연계형 인턴십) (0) | 2023.10.31 |
[프로그래머스/Python] Level 2_2개 이하로 다른 비트 (월간 코드 챌린지 시즌 2) (0) | 2023.10.31 |
Comments