코딩 테스트
-
프로그래머스 / 문자열 나누기코딩 테스트/Level 1 2022. 12. 2. 20:25
https://school.programmers.co.kr/learn/courses/30/lessons/140108 파이썬 def solution(s): first = s[0] new_index = slices = same = no_same = 0 for index, each in enumerate(s): new_index += 1 if each == first: same += 1 else: no_same += 1 if same == no_same: slices += 1 new_index = same = no_same = 0 if index + 1 < len(s): first = s[index + 1] return slices + (1 if new_index else 0) def solution(s): ..
-
숫자 타자 대회코딩 테스트/Level 3 2022. 11. 30. 13:00
https://school.programmers.co.kr/learn/courses/30/lessons/136797 간단히 완전 탐색. 당연히 시간 제한. 문제는 제대로 이해한 것 같고.. def solution(numbers): def search(left, right, index, total): if len(numbers) == index: return total if left == right: return float('inf') number = int(numbers[index]) left_total = search(number, right, index + 1, total) + weights[left][number] right_total = search(left, number, index + 1, t..
-
등대코딩 테스트/Level 3 2022. 11. 27. 13:09
https://school.programmers.co.kr/learn/courses/30/lessons/133500 def solution(n, lighthouse): def make_tree(): tree = [[] for _ in range(n + 1)] for a, b in lighthouse: tree[a].append(b) tree[b].append(a) return tree def dfs(node, tree, visited): visited[node] = True children = [next_node for next_node in tree[node] if not visited[next_node]] on, off = 1, 0 if not children: return on, off else: ..
-
억억단을 외우자코딩 테스트/Level 3 2022. 11. 25. 01:15
https://school.programmers.co.kr/learn/courses/30/lessons/138475 def solution(e, starts): divisors = [0 for _ in range(e + 1)] for i in range(1, e + 1): for j in range(i, e + 1): if (temp := i * j) > e: break divisors[temp] += 1 if i == j else 2 checker = [0] * (e + 1) # [0 for _ in range(e + 1)] max_num = 0 for index in range(e, 0, -1): if divisors[index] >= max_num: max_num = divisors[index] c..
-
귤 고르기코딩 테스트/Level 2 2022. 11. 25. 00:00
https://school.programmers.co.kr/learn/courses/30/lessons/138476 def solution(k, tangerine): from collections import Counter total, count = 0, Counter(tangerine) for index, each in enumerate(sorted(count.values(), reverse=True)): total += each if total >= k: return index + 1 return k 테스트 1 〉통과 (5.43ms, 13MB) 테스트 2 〉통과 (5.33ms, 13.3MB) 테스트 3 〉통과 (9.67ms, 13.2MB) 테스트 4 〉통과 (6.51ms, 13.1MB) 테스트 5 〉..
-
프로그래머스 / 명예의 전당 (1)코딩 테스트/Level 1 2022. 11. 24. 22:13
https://school.programmers.co.kr/learn/courses/30/lessons/138477 파이썬 힙큐를 이용하면 조금 빠르려나... def solution(k, score): import heapq answer, honer = [], [] for each in score: heapq.heappush(honer, each) if len(honer) > k: heapq.heappop(honer) answer.append(honer[0]) # honer[0] = 가장 작은 원소 return answer 테스트 1 〉통과 (0.01ms, 10MB) 테스트 2 〉통과 (0.01ms, 10.1MB) 테스트 3 〉통과 (0.01ms, 10.1MB) 테스트 4 〉통과 (0.01ms, 9.97..
-
카운트 다운코딩 테스트/Level 3 2022. 11. 24. 01:32
https://school.programmers.co.kr/learn/courses/30/lessons/131129 def solution(target): import sys import heapq def dp(rest_score): if rest_score == 0: return 0, 0 if memo[rest_score]: return memo[rest_score] heap = [] for score in scores: if score == 50 and (next_score := rest_score - 50) >= 0: temp = dp(next_score) heapq.heappush(heap, (temp[0] + 1, temp[1] - 1)) continue if (next_score := rest..