코딩 테스트/Level 2
-
프로그래머스 / 두 원 사이의 정수코딩 테스트/Level 2 2023. 4. 15. 15:54
https://school.programmers.co.kr/learn/courses/30/lessons/181187 파이썬 def solution(r1, r2): answer = 0 pow_r1, pow_r2 = r1 ** 2, r2 ** 2 for y in range(1, r2 + 1): temp1 = pow_r1 - y ** 2 if temp1 >= 0: temp2 = temp1 ** 0.5 x1 = int(temp2) - (1 if temp2 == int(temp2) else 0) else: x1 = -1 answer += int((pow_r2 - y ** 2) ** 0.5) - x1 return answer * 4
-
프로그래머스 / 연속된 부분 수열의 합코딩 테스트/Level 2 2023. 4. 11. 23:29
https://school.programmers.co.kr/learn/courses/30/lessons/178870 파이썬 이렇게 쉽게는 넘어가지 않겠지.. def solution(sequence, k): answer = [] for i in range(len(sequence)): for j in range(i + 1, len(sequence) + 1): s = sum(sequence[i:j]) if s == k: answer.append([i, j - 1]) elif s > k: break return sorted(answer, key=lambda x: x[1] - x[0])[0] 소티드를 이용해서 간결하게.. def solution(sequence, k): answer = [] left = right..
-
프로그래머스 / 과제 진행하기코딩 테스트/Level 2 2023. 4. 1. 13:22
https://school.programmers.co.kr/learn/courses/30/lessons/176962 파이썬 def solution(plans): timeline = [] plans2 = map(lambda x: (x[0], int(x[1][0]) * 60 + int(x[1][1]), x[2]), map(lambda x: (x[0], x[1].split(':'), int(x[2])), plans)) for name, start, playtime in sorted(plans2, key=lambda x: x[1]): for index, each in enumerate(timeline): if each[1] > start: timeline[index][1] += playtime timeline...
-
프로그래머스 / 광물 캐기코딩 테스트/Level 2 2023. 3. 24. 15:21
https://school.programmers.co.kr/learn/courses/30/lessons/172927 파이썬 제안사항을 확인하니 재귀를 이용해도 될 정도 def solution(picks, minerals): def solve(picks, minerals, fatigue): if sum(picks) == 0 or len(minerals) == 0: return fatigue result1 = result2 = result3 = float('inf') if picks[0] > 0: fatigues = {"diamond": 1, "iron": 1, "stone": 1} next_fatigue = sum(fatigues[mineral] for mineral in minerals[:5]) resu..
-
프로그래머스 / 리코쳇 로봇코딩 테스트/Level 2 2023. 3. 17. 16:06
https://school.programmers.co.kr/learn/courses/30/lessons/169199 주의할 점. 목표도 통과해 버린다. 목표에 멈출 수 있어야 성공~! 파이썬 def solution(board): que = [] for x, row in enumerate(board): for y, each in enumerate(row): if each == 'R': que.append((x, y, 0)) visited = set() while que: x, y, length = que.pop(0) if (x, y) in visited: continue if board[x][y] == 'G': return length visited.add((x, y)) for diff_x, diff_y ..
-
프로그래머스 / 덧칠하기코딩 테스트/Level 2 2023. 3. 4. 00:40
https://school.programmers.co.kr/learn/courses/30/lessons/161989 이게 왜 level 2? 쉬운데... 코틀린 class Solution { fun solution(n: Int, m: Int, section: IntArray): Int { var (answer, painted) = 0 to 0 for (each in section) if (each >= painted) { painted = m + each answer++ } return answer } } golang func solution(n int, m int, section []int) int { answer, painted := 0, 0 for _, v := range section { if v..
-
코딩테스트 / 혼자서 하는 틱택토코딩 테스트/Level 2 2023. 2. 25. 18:16
https://school.programmers.co.kr/learn/courses/30/lessons/160585 이런저런 케이스를 다 생각해서 풀어야 하는 문제... 1. 선공인 O와 후공인 X의 개수가 1 이상 나면 안 된다. 2. O와 X가 동시에 이겨서는 안 된다. 3. O가 이겼을 때 다음 X는 없다. 그러므로 O가 X보다 1개 많아야.. 4. X가 이겼을 때 다음 O는 없다. 그러므로 O와 X의 개수가 같아야.. 코틀린 class Solution { private fun countMarker(board: Array): Pair { var (oCounter, xCounter) = arrayOf(0, 0) for (line in board) for (each in line) if (each ==..