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

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

# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def leafSimilar(self, root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool: # 주어진 트리의 리프 노드(leaf node) 값을 순서대로 가져오는 함수 def get_leaf_sequence(root: Optional[TreeNode]) -> ..

https://neetcode.io/problems/binary-tree-right-side-view NeetCode neetcode.io첫번째 풀이 방법: BFS - Level Order Traversal각 레벨에서 가장 오른쪽에 있는 노드의 값만 저장하면 된다.BFS(너비 우선 탐색, Queue;)을 이용하여 레벨별 탐색을 수행한다.매 레벨의 마지막 노드 값을 결과 리스트에 추가한다.# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right =..