일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 파이썬
- 릿코드
- dfs
- 파이썬알고리즘
- 니트코드
- nlp
- 구글퀵랩
- Python
- 투포인터
- 슬라이딩윈도우
- 리트코드
- sql코테
- slidingwindow
- GenAI
- Microsoft
- heap
- 알고리즘
- 생성형AI
- stratascratch
- two-pointer
- medium
- 파이썬기초100제
- Python3
- 자연어처리
- GenerativeAI
- codeup
- SQL
- LeetCode
- 코드업
- gcp
- Today
- Total
목록heap (8)
Tech for good

🌷 Subarray vs Subsequence"Do I need to pick connected elements?" - have to be contiguousSubarrayEx) arr = [1, 2, 3, 4]❌ [1, 3] is not valid — skips 2"Can I pick elements freely as long as I keep the order?"- do not have to be contiguousSubsequence✅ [1, 4] is valid — it's in the correct order. ✅ Code OverviewYou're implementing a sliding window approach, where:You track the maximum and minimum v..

https://neetcode.io/problems/kth-largest-integer-in-a-stream NeetCode neetcode.io ✅ 문제 요약KthLargest라는 클래스를 만들어야 한다. 이 클래스는 다음 두 가지 기능을 제공한다:생성자 KthLargest(k, nums)→ 처음에 k번째로 큰 수를 추적할 수 있도록 정수 배열 nums를 받고 초기화한다.add(val) 메서드→ 새로운 값을 스트림(데이터 흐름)에 추가하고, 현재까지의 숫자들 중에서 k번째로 큰 수를 반환한다.📌 "k번째로 큰 수"란?숫자들을 내림차순으로 정렬했을 때, k번째에 오는 숫자를 말한다.예: nums = [1, 2, 3, 3], k = 2라면정렬: [3, 3, 2, 1] → 두 번째로 큰 수는 3이다.💡 ..

🌷 Looking into Example -> Key is to return the furthest building indexExample 1:heights = [4, 2, 7, 6, 9, 14, 12], bricks = 5, ladders = 14 -> 2 (X)2 -> 7 (5) (Ladder)7 -> 6 (X)6 -> 9 (3) (Bricks 3)9 -> 14 (5) (Bricks 2; shortage of bricks)14 -> 12 (X)Thus, you can move by [4, 2, 7, 6, 9](Index) 0 1 2 3 4Example 2:heights = [4, 12, 2, 7, 3, 18, 20, 3, 19], bric..

class Solution: def getFinalState(self, nums: List[int], k: int, multiplier: int) -> List[int]: n = len(nums) # Build a heap of (value, index) for index tracking heap = [(nums[i], i) for i in range(n)] heapq.heapify(heap) for _ in range(k): while True: val, idx = heapq.heappop(heap) # Check if the heap value m..

1. Sort✅ Approach:Sort the array first to make it easy to remove the minimums.In every round:Alice removes the smallest number (i.e., pop from the front).Bob removes the next smallest number.Bob appends his number first, then Alice.class Solution: def numberGame(self, nums: List[int]) -> List[int]: nums.sort() arr = [] while nums: alice = nums.pop(0) # Alice r..

You can solve this problem by:Finding the k largest elements based on value (to maximize the sum).Preserving their original order in the array (since it's a subsequence).class Solution: def maxSubsequence(self, nums: List[int], k: int) -> List[int]: # Step 1: Pair each element with its original index indexed_nums = list(enumerate(nums)) # Step 2: Select the k larg..

class Solution: def maxProduct(self, nums: List[int]) -> int: # Convert to max-heap by pushing negative values max_heap = [-num for num in nums] heapq.heapify(max_heap) # Pop the two largest values first_max = -heapq.heappop(max_heap) second_max = -heapq.heappop(max_heap) return (first_max - 1) * (second_max - 1)

https://neetcode.io/problems/k-closest-points-to-origin NeetCode neetcode.io큐(Queue)는 선입선출(First In, First Out, FIFO)의 자료 구조로, 먼저 들어온 데이터가 먼저 나간다. 하지만 우선순위가 있는 작업에서는 큐의 기본 원칙을 따르지 않을 때가 있다. 우선순위 큐(Priority Queue) 는 들어온 순서와 상관없이 우선순위가 높은 데이터가 먼저 나가는 자료 구조다.힙( Heap)이란?힙(Heap)은 우선순위 큐를 구현하기 위한 자료 구조다. 힙의 뜻을 살펴보면, "쌓아 올린 더미" 또는 "쌓아 올리다"라는 의미를 가진다. 힙은 최댓값과 최솟값을 찾는 연산을 빠르게 하기 위해 고안된 완전 이진 트리를 기본으로 한며,..