일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Decorator
- 43. Multiply Strings
- 밴픽
- kaggle
- Class
- 운영체제
- 715. Range Module
- Substring with Concatenation of All Words
- Convert Sorted List to Binary Search Tree
- concurrency
- Python
- iterator
- 315. Count of Smaller Numbers After Self
- Python Code
- Regular Expression
- Protocol
- Generator
- 30. Substring with Concatenation of All Words
- shiba
- 파이썬
- 109. Convert Sorted List to Binary Search Tree
- t1
- 시바견
- data science
- Python Implementation
- 컴퓨터의 구조
- 프로그래머스
- attribute
- DWG
- LeetCode
- Today
- Total
목록Computer Science/Coding Test (225)
Scribbling
https://leetcode.com/problems/the-earliest-moment-when-everyone-become-friends/description/ LeetCode - The World's Leading Online Programming Learning Platform Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com class Solution: def earliestAcq(self, logs: List[List[int]], n: int) -> int: parent..
Q: Given arbitrary ranges, merge all the ranges that overlap with each other. Return the resultant ranges. 1. Sort all the ranges by their start and end. 2. Now that we know that range's start increases we have to take care of the ends --> We have to take care of the two cases below. 3. Code ranges = [] ranges.append(schedules[0]) for s, e in schedules: if s '[Interval]': schedules = [] for i in..
Q: Find the number of unique strings of which the length is L, given that the maximum number of consecutive vowels allowed is K. * There are 21 types of consonants and 5 types of vowels. For example, L=4, K=1: then allowed patterns are - CCCC CCCV, CCVC, CVCC, VCCC, VCVC, VCCV, CVCV This question can be easily handled with DFS. However, the approach would not be optimal as it involves unnecessar..
For a given recipe, we need to check whether all the necessary elements can be supplied. If an element belongs to supplies, it's a piece of cake. Now the question is to deal with elements that belong to recipes. We can think of recipes as a graph with cycles. Plus, if there's a cycle among certain recipes, they can never be cooked. class Solution: def findAllRecipes(self, recipes: List[str], ing..
First thing I came out with was to use a trie data structure, as it helps us deal with characters efficiently. class StreamChecker: def __init__(self, words: List[str]): self.trie = {} for word in words: node = self.trie for char in word: if char not in node: node[char] = {} node = node[char] node['#'] = '#' self.candidates = [] def query(self, letter: str) -> bool: self.candidates.append(self.t..
1. Using heaps with lazy removal Below code uses 'MyHeap' data structure, a heap with lazy removal. Lazy removal here means, if we have to remove an element, we handle it by using another heap as a trash can. import heapq class MyHeap: def __init__(self, type='min'): self.heap = [] self.removals = [] self.sign = 1 if type == 'min' else -1 def insert(self, elem): heapq.heappush(self.heap, self.si..
We need to deal with ranges to solve this problem. Below is the link of a wonderful solution. https://leetcode.com/problems/range-module/discuss/244194/Python-solution-using-bisect_left-bisect_right-with-explanation Python solution using bisect_left, bisect_right with explanation - LeetCode Discuss Level up your coding skills and quickly land a job. This is the best place to expand your knowledg..
The very first thing to do is looking for matches. We don't need to use any fancy algorithms when looking for matches in this problem because it is guranteed that replacements will not overlap. Now we have matched list in the form of [index, source, target]. If you are planning to replace s directly, it will lead to bad time complexity as you will have to copy all the characters of s each time y..
class Solution: def calculate(self, s: str) -> int: # ' ' is intentionally added, # to mark the end of the given string s # encountering ' ' will add the last number to the stack self.s = s + ' ' self.ptr = 0 return self.calc() def calc(self): num, stack, sign = 0, [], '+' while self.ptr < len(self.s): c = self.s[self.ptr] # if met with '(', # get the evaluated number by recursion if c == '(': s..
Using double trie structures for prefix and suffix. Somewhat straightforward if one already knows about trie. If not, refer to "LeetCode prob 208. Implement Trie (Prefix Tree)". class WordFilter: def __init__(self, words: List[str]): wordDict = {} for idx, word in enumerate(words): wordDict[word] = idx self.PrefixTree = {} self.SuffixTree = {} for word, idx in wordDict.items(): node = self.Prefi..