목록programmers (70)
컴공생의 다이어리

[프로그래머스] 실패율 - 파이썬(Python) import collections def solution(N, stages): total_people = len(stages) stage_count = dict(collections.Counter(stages)) result = [] for i in range(1, N + 1): if i in stage_count.keys(): result.append((i, stage_count[i] / total_people)) total_people -= stage_count[i] else: result.append((i, 0)) result.sort(key=lambda x: (-x[1], x[0])) return [x for x, _ in result] https:..

[프로그래머스] 오픈채팅방 - 파이썬(Python) def solution(record): answer = [] id_dict = dict() # id에 해당하는 이름 정보 commands = [list(r.split()) for r in record] # record의 데이터들을 공백 기준으로 분리 for command in commands: if command[0] == 'Enter' or command[0] == 'Change': # id에 해당하는 닉네임 정보 생성 혹은 업데이트 id_dict[command[1]] = command[2] for command in commands: if command[0] == 'Enter': answer.append(id_dict[command[1]] + "님이..

[프로그래머스] 방문 길이 - 파이썬(Python) def solution(dirs): move = {'U': (0, 1), 'D': (0, -1), 'R': (1, 0), 'L': (-1, 0)} answer = set() pos_x, pos_y = 0, 0 for i in dirs: x, y = move[i][0], move[i][1] if -5

[프로그래머스] 더 맵게 - 파이썬(Python) import heapq def solution(scoville, K): heapq.heapify(scoville) count = 0 while len(scoville) >= 2 and scoville[0] = K else -1 혹은 import heapq def solution(scoville, K): heapq.heapify(scoville) count = 0 while sco..

[프로그래머스] K번째수 - 파이썬(Python) def solution(array, commands): answer = [] for i, j, k in commands: answer.append(sorted(array[i - 1:j])[k - 1]) return answer https://programmers.co.kr/learn/courses/30/lessons/42748 코딩테스트 연습 - K번째수 [1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3] programmers.co.kr

[프로그래머스] 주식가격 - 파이썬(Python) from collections import deque def solution(prices): queue = deque(prices) answer = [] while queue: price = queue.popleft() sec = 0 for q in queue: sec += 1 if price > q: break answer.append(sec) return answer https://programmers.co.kr/learn/courses/30/lessons/42584 코딩테스트 연습 - 주식가격 초 단위로 기록된 주식가격이 담긴 배열 prices가 매개변수로 주어질 때, 가격이 떨어지지 않은 기간은 몇 초인지를 return 하도록 solution 함수..

[프로그래머스] 다리를 지나는 트럭 - 파이썬(Python) def solution(bridge_length, weight, truck_weights): on_bridge = [0] * bridge_length answer = 0 while on_bridge: answer += 1 on_bridge.pop(0) if truck_weights: if sum(on_bridge) + truck_weights[0]

[프로그래머스] 프린터 - 파이썬(Python) def solution(priorities, location): priorities = [(v, idx) for idx, v in enumerate(priorities)] count = 0 while True: if priorities[0][0] == max(priorities)[0]: count += 1 if priorities[0][1] == location: break priorities.pop(0) else: priorities.append(priorities.pop(0)) return count https://programmers.co.kr/learn/courses/30/lessons/42587 코딩테스트 연습 - 프린터 일반적인 프린터는 인쇄 요..

[프로그래머스] 기능개발 - 파이썬(Python) import math def solution(progresses, speeds): answer = [] progress_day = [math.ceil((100 - x) / y) for x, y in zip(progresses, speeds)] count = 0 for i in progress_day: if i > count: answer.append(1) count = i else: answer[-1] += 1 return answer https://programmers.co.kr/learn/courses/30/lessons/42586 코딩테스트 연습 - 기능개발 프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비..

[프로그래머스] 베스트앨범 - 파이썬(Python) from collections import defaultdict def solution(genres, plays): answer = [] G = defaultdict(int) detail = defaultdict(list) for idx, [g, p] in enumerate(zip(genres, plays)): G[g] += p detail[g].append((p, idx)) for g, _ in sorted(G.items(), key=lambda x: -x[1]): for _, i in sorted(detail[g], key=lambda x: -x[0])[:2]: answer.append(i) return answer 혹은 from collection..