일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- heap
- two-pointer
- 알고리즘
- SQL
- 니트코드
- slidingwindow
- 투포인터
- 릿코드
- 자연어처리
- medium
- 파이썬기초100제
- GenAI
- 생성형AI
- sql코테
- 구글퀵랩
- 파이썬
- 슬라이딩윈도우
- 코드업
- dfs
- stratascratch
- codeup
- Python
- gcp
- GenerativeAI
- Python3
- nlp
- Microsoft
- 파이썬알고리즘
- LeetCode
- 리트코드
- Today
- Total
목록MaxHeap (3)
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..

Example 1:gifts = [25, 64, 9, 4, 100], k = 4[25, 64, 9, 4, 100]-> (1회) [25, 64, 9, 4, 10]-> (2회) [25, 8, 9, 4, 10]-> (3회) [5, 8, 9, 4, 10]-> (4회) [5, 8, 9, 4, 3] (floor or the square root - floor: 내림)5 + 8 + 9 + 4 + 3 = 29 Follow these steps:Pick the largest pile of gifts.Replace it with the floor of its square root.Repeat this for k seconds.🔧 Best Tool for This?We need to efficiently get the l..

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)