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

https://neetcode.io/problems/last-stone-weight NeetCode neetcode.io🧩 문제 요약당신은 여러 개의 돌(stone)을 가지고 있고, 각 돌에는 무게가 있다.이 돌들을 다음 규칙에 따라 하나 또는 없을 때까지 부딪혀 없애는 시뮬레이션을 한다:🔨 시뮬레이션 규칙매 단계에서 가장 무거운 두 개의 돌을 선택한다. (x, y, 단, x ≤ y)두 돌을 서로 부딪힌다:x == y → 둘 다 파괴됨 (삭제)x != y → 작은 돌 x는 파괴되고, 큰 돌 y는 y - x 무게로 바뀜위 과정을 돌이 하나 이하로 남을 때까지 반복한다.🎯 최종 목표돌이 마지막에 하나 남으면 그 돌의 무게를 반환하고,아무것도 안 남으면 0을 반환한다.🔍 예제 설명예제 1:Input: ..

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 frequencySort(self, s: str) -> str: # Step 1: Count frequency of each character freq = Counter(s) # Step 2: Build max-heap based on frequency # Use -count to simulate max-heap heap = [(-count, char) for char, count in freq.items()] heapq.heapify(heap) # Step 3: Build the result string from the heap result = []..

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..

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..

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)은 우선순위 큐를 구현하기 위한 자료 구조다. 힙의 뜻을 살펴보면, "쌓아 올린 더미" 또는 "쌓아 올리다"라는 의미를 가진다. 힙은 최댓값과 최솟값을 찾는 연산을 빠르게 하기 위해 고안된 완전 이진 트리를 기본으로 한며,..