728x90

전체 글 206

heapq와 deque의 차이

deque - 선입선출 - 동적 배열인 리스트는 큐연산에적합하지 않아 데크를 써야 좋은 성능을낼 수있음 - 양쪽 끝을 모두 추출할 수 있음 - BFS from collections import deque q=deque() q.append('l') q.popleft() heapq - 우선순위 큐 - 최소힙, 최대힙 - 최단경로 탐색하는 다익스트라, 최소값이나 최대값을 빨리 찾아야 할 때 - heappop()을 할 경우 가장 작은 원소부터 추출됨 from heapq import heappush, heappop, heapify q=[] heappush(q, 1) heappop(q) heapify(arr) Tuple보다는 List가 더 느리기 때문에, 해당 코드의 우선순위 큐에 넣는 원소를 []가 아닌 ()로 ..

[HackerRank] Weather Observation Station 5

https://www.hackerrank.com/challenges/weather-observation-station-5/problem?isFullScreen=true Weather Observation Station 5 | HackerRank Write a query to print the shortest and longest length city name along with the length of the city names. www.hackerrank.com STATION에서 가장 짧고 긴 CITY 이름과 각각의 길이 (즉, 이름에 포함된 문자 수)를 찾아라. 가장 작은 도시나 가장 큰 도시가 두 개 이상 있는 경우 알파벳 순으로 정렬할 때 가장 먼저 오는 도시를 선택하라. WITH CNT_TAB ..

𝙎𝙌𝙇 2023.08.09

[HackerRank] Interviews

https://www.hackerrank.com/challenges/interviews/problem?isFullScreen=true Interviews | HackerRank find total number of view, total number of unique views, total number of submissions and total number of accepted submissions. www.hackerrank.com Samantha는 코딩 챌린지와 컨테스트를 통해 여러 대학의 많은 후보자를 인터뷰합니다. contest_id, hacker_id, name과 각 컨테스트 별 total_submissions, total_accepted_submissions, total_views, total..

𝙎𝙌𝙇 2023.08.03

[Programmers] 의상 (해시)

https://school.programmers.co.kr/learn/courses/30/lessons/42578 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(clothes): answer = 1 clothe = {k:[] for _,k in clothes} for name, kind in clothes : clothe[kind].append(name) for v in clothe.values() : answer *= (len(v) + 1) return answer - 1 다른 분들이 푸신 해설을 보다가 도움이 되는 설명이 있어서..

[Programmers] 가장 큰 수 (정렬)

https://school.programmers.co.kr/learn/courses/30/lessons/42746 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(numbers): return ''.join(map(str, sorted(numbers, key=lambda x : (str(x)[0], str(x), str(x)[-1]), reverse=True))) 실패할 줄 알았던... ㅎㅎ 결국 다른 사람의 힌트를 참고함! def solution(numbers): numbers = list(map(str, numbers)) numb..

[Programmers] K번째수 (정렬)

https://school.programmers.co.kr/learn/courses/30/lessons/42748 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr def solution(array, commands): answer = [] for a, b, c in commands : answer.append(sorted(array[a-1 : b])[c-1]) return answer

[HackerRank] Placements

https://www.hackerrank.com/challenges/placements/problem?isFullScreen=true Placements | HackerRank Write a query to output the names of those students whose best friends got offered a higher salary than them. www.hackerrank.com 베스트 프렌드가 자신보다 더 높은 salary를 받는 학생들의 이름을 출력. 베스트 프렌드가 받는 salary를 오름차순으로 정렬. (동일한 값의 salary는 없음) select s.name from students s left join friends f on s.id = f.id left join p..

𝙎𝙌𝙇 2023.07.27

[HackerRank] SQL Project Planning

https://www.hackerrank.com/challenges/sql-projects/problem?isFullScreen=true SQL Project Planning | HackerRank Write a query to output the start and end dates of projects listed by the number of days it took to complete the project in ascending order. www.hackerrank.com 주어진 테이블에 start_date와 end_date라는 컬럼이 있는데, 같은 행의 두 원소는 무조건 하루가 차이 난다. 이때, 연속하는 날짜의 행은 같은 프로젝트이다. 프로젝트가 시작하는 날짜와 끝나는 날짜를 찾고 걸린 기간에..

𝙎𝙌𝙇 2023.07.26
728x90