반응형

Python 8

서비스기업 알고리즘 기출 문제[dp, 누적 합]

문제 설명 어떤 사람이 자신의 하루가 끝나면 '하루의 행복도'를 0에서 10사이의 점수로 기록했습니다. 어느 날 그동안 기록했던 행복도 점수를 보고, 문득 가장 행복했던 리즈 시절이 언제인지 궁금했습니다. 가장 긴 리즈 시절의 기간을 찾으세요. 리즈 시절 조건 행복도가 8 보다 크면 행복한 날로 판단합니다. 리즈 시절 기간 중 행복한 날이 행복하지 않은 날보다 많아야 합니다. 리즈 시절은 연속된 기간입니다. 예시) 입력: happiness = [9,10,6,0,4,6,10] 출력: 3 설명: 가장 긴 리즈 시절은 [9, 10,6] 입니다. 행복한 날이 2번 있으므로 불행한 날이 하루 있어도 됩니다. 제약사항 1 0 else 0 for i in range(0,len(l)): for j in range(0,..

알고리즘 2023.04.01

프로그래머스(programmers) 더 맵게 python 정답 [힙(heap)]

프로그래머스(programmers) 더 맵게 python 정답 [힙(heap)] 문제 링크 https://school.programmers.co.kr/learn/courses/30/lessons/42626 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 정답 입출력 예 scoville K return [1, 2, 3, 9, 10, 12] 7 2 정답 코드 from heapq import heappush,heapify,heappop def solution(scoville, K): answer = 0 q = scoville[:] heapify(q) whi..

알고리즘 2023.03.17

프로그래머스(programmers) H-index python 정답 [정렬]

프로그래머스(programmers) H-index python 정답 [정렬] 문제 링크 https://school.programmers.co.kr/learn/courses/30/lessons/42747 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 정답 입출력 예 citations return [3, 0, 6, 1, 5] 3 정답 코드 def solution(citations): return len(list(filter(lambda x : x[0]

알고리즘 2023.03.17

프로그래머스(programmers) K번째수 python 정답 [정렬]

프로그래머스(programmers) K번째수 python 정답 [정렬] 문제 링크 https://school.programmers.co.kr/learn/courses/30/lessons/42748 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 정답 입출력 예 array commands return [1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3] 정답 코드 def solution(array, commands): def mapCommand(command): [s,e,k] = comma..

알고리즘 2023.03.16

프로그래머스(programmers) 가장 큰 수 python 정답 [정렬]

프로그래머스(programmers) 가장 큰 수 python 정답 [정렬] 문제 링크 https://school.programmers.co.kr/learn/courses/30/lessons/42746 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 정답 입출력 예 문제 이미지 numbers return [6, 10, 2] "6210" [3, 30, 34, 5, 9] "9534330" 정답 코드 import functools def comparator(a,b): t1 = a+b t2 = b+a return (int(t1) < int(t2)) - (int..

알고리즘 2023.03.16

프로그래머스(programmers) 모음사전 python 정답 [완전 탐색]

프로그래머스(programmers) 모음사전 python 정답 [완전 탐색] 문제 링크 https://school.programmers.co.kr/learn/courses/30/lessons/84512 문제 정답 입출력 예 word result "AAAAE" 6 "AAAE" 10 "I" 1563 "EIO" 1189 정답 코드 def solution(word): answer = 0 for i, n in enumerate(word): answer += (5 ** (5 - i) - 1) / (5 - 1) * "AEIOU".index(n) + 1 return answer 문제 해설 https://seongho96.tistory.com/50 [JAVA 풀이] 프로그래머스 - 모음사전 (Level 2) 코딩테스트 ..

알고리즘 2023.03.16

프로그래머스(programmers) 전력망을 둘로 나누기 python 정답 [완전 탐색]

프로그래머스(programmers) 전력망을 둘로 나누기 python 정답 [완전 탐색] 문제 링크 https://school.programmers.co.kr/learn/courses/30/lessons/86971 문제 정답 입출력 예 n wires result 9 [[1,3],[2,3],[3,4],[4,5],[4,6],[4,7],[7,8],[7,9]] 3 4 [[1,2],[2,3],[3,4]] 0 7 [[1,2],[2,7],[3,7],[3,4],[4,5],[6,7]] 1 정답 코드 from collections import deque def bfs(start,visitied,graph): queue = deque([start]) result = 1 visitied[start] = True while q..

알고리즘 2023.03.16

프로그래머스(programmers) 피로도 python 정답 [완전 탐색]

프로그래머스(programmers) 피로도 python 정답 [완전 탐색] 문제 링크 https://school.programmers.co.kr/learn/courses/30/lessons/87946 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 문제 정답 입출력 예 k dungeons result 80 [[80,20],[50,40],[30,10]] 3 정답 코드 def solution(k, dungeons): return dfs(k,dungeons) def dfs(k,dungeons,answer=0): # base condition if not dung..

알고리즘 2023.02.21
반응형