본문 바로가기

코딩 테스트17

[문제 풀이 22] 코드 트리 - 색맹 색맹 문제 유형 : DFS 사용언어 : Python 난이도 : 실버 1 출처 : 코드 트리 https://www.codetree.ai/training-field/search/problems/color-blindness?&utm_source=clipboard&utm_medium=text 코드트리 | 코딩테스트 준비를 위한 알고리즘 정석 국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요. www.codetree.ai def dfs(grid, visited, x, y, n): stack = [(x, y)] size = 0 color = grid[x][y] while stack: cx, cy = stack.pop() if visited[c.. 2024. 4. 22.
[문제 풀이 20] 코드 트리 - 연결된 칸 찾기 연결된 칸 찾기 문제 유형 : DFS 사용언어 : Python 난이도 : 실버 1 출처 : 코드 트리 def dfs(grid, visited, x, y, n): stack = [(x, y)] size = 0 # 연결된 1의 개수를 세는 변수 while stack: cx, cy = stack.pop() if visited[cx][cy]: continue visited[cx][cy] = True size += 1 # 상, 하, 좌, 우 네 방향으로 이동 가능 for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: nx, ny = cx + dx, cy + dy if 0 2024. 4. 19.
[문제 풀이 18] 코드 트리 - 정수 두 개의 합 정수 두 개의 합 문제 유형 : HashMap 사용언어 : Python 난이도 : 실버 4 출처 : 코드 트리 https://www.codetree.ai/training-field/search/problems/sum-of-two-integers?&utm_source=clipboard&utm_medium=text 코드트리 | 코딩테스트 준비를 위한 알고리즘 정석 국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요. www.codetree.ai n = int(input()) m = int(input()) arr = list(map(int, input().split())) def count_sort(arr, m): hash_table = .. 2024. 4. 18.
[문제 풀이 16] 프로그래머스 - 카드 뭉치 카드 뭉치 문제 유형 : 큐 사용언어 : Python 난이도 : LV. 1 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/159994 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(cards1, cards2, goal): for g in goal: if len(cards1) > 0 and g == cards1[0]: cards1.pop(0) elif len(cards2) > 0 and g == cards2[0]: cards2.pop(0) else: ret.. 2024. 4. 17.
[문제 풀이 15] 코드 트리 - 섞기 전 카드 위치 섞기 전 카드 위치 문제 유형 : Simulation 사용언어 : Python 난이도 : 실버 5 출처 : 코드 트리 https://www.codetree.ai/training-field/search/problems/card-position-before-shuffling?&utm_source=clipboard&utm_medium=text 코드트리 | 코딩테스트 준비를 위한 알고리즘 정석 국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요. www.codetree.ai n = int(input()) # Before shuffle location = list(map(int, input().split())) card = list(map(i.. 2024. 4. 17.
[문제 풀이 14] 프로그래머스 - 기능 개발 기능 개발 문제 유형 :큐 사용언어 : Python 난이도 : LV. 2 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/42586 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr import math def solution(progresses, speeds): answer = [] n = len(progresses) days_left = [math.ceil((100-progresses[i])/ speeds[i]) for i in range(n)] count = 0 max_day .. 2024. 4. 16.
[문제 풀이 13] 코드 트리 - 오목의 승패 오목의 승패 문제 유형 : Simulation, BFS 사용언어 : Python 난이도 : 실버 3 출처 : 코드 트리 https://www.codetree.ai/training-field/my-lists/20228/concave-victory-and-defeat/description 코드트리 | 코딩테스트 준비를 위한 알고리즘 정석 국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요. www.codetree.ai def bfs(x, y): target = graph[x][y] for dx, dy in direction: cnt = 1 nx = x + dx ny = y + dy while 0 2024. 4. 16.
[문제 풀이 11] 프로그래머스 - 표 편집 표 편집 문제 유형 : Linked List, Stack 사용언어 : Python 난이도 : LV. 3 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/81303 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(n, k, cmd): state = ["O"] * n # 링크드 리스트 구성 요소 nodes = {i: {'prev': i-1, 'next': i+1} for i in range(n)} nodes[0]['prev'] = None nodes[n-1]['.. 2024. 4. 13.
[문제 풀이 9] 코드 트리 - 연쇄로 터지는 폭탄 연쇄로 터지는 폭탄 문제 유형 : Simulation, Exhaustive Search 사용언어 : Python 난이도 : 실버 4 출처 : 코드 트리 https://www.codetree.ai/training-field/search/problems/series-of-bombs-detonating?&utm_source=clipboard&utm_medium=text 코드트리 | 코딩테스트 준비를 위한 알고리즘 정석 국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요. www.codetree.ai n = int(input()) positions = [int(input()) for _ in range(n)] # 폭탄의 위치 position.. 2024. 4. 12.
[문제 풀이 8] 프로그래머스 - 크레인 인형 뽑기 게임 크레인 인형 뽑기 게임 문제 유형 : Stack 사용언어 : Python 난이도 : LV. 1 출처 : 프로그래머스 https://school.programmers.co.kr/learn/courses/30/lessons/64061 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(board, moves): answer = 0 r=len(board) c=len(board[0]) basket = [] for m in moves: for i in range(len(board)): if board[i][m-1] !=0: basket.appen.. 2024. 4. 12.