```python class Solution: def maxEvents(self, events: List[List[int]]) -> int: “”” 1. sort by start 2. put the end time of events starting before current date into PQ 3. pop events that end earlier than current date off the PQ 4. cnt + 1, date +1, pop one event out “””...
[Read More]
315. Count of Smaller Numbers After Self
class Solution: def countSmaller(self, A: List[int]) -> List[int]: n = len(A) res = [0] * n B = [] for i, v in enumerate(A): B.append((v,i)) def merge(l_arr, r_arr): """tc O(NlgN) sc O(N) 1. when both left array and right array is not running out, compare left[l] with right[r], move it...
[Read More]
472. Concatenated Words
Top Down class Solution: def findAllConcatenatedWordsInADict(self, words: List[str]) -> List[str]: """tc O(N*W^2*2^W) sc O(N*W^2*2^W)?? O(N*W^2) W: avg len of word main idea: dfs + memo 1. create a global memo, put all words into set for O(1) look up 2. loop through all the words and check if it can...
[Read More]
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
class Solution: def maxArea(self, h: int, w: int, hh: List[int], ww: List[int]) -> int: """tc O(NlgN) sc O(1) 1. sort height and width 2. find max height and and max width, note the edge width and edge height 3. get the max area = max_height * max_width """ M =...
[Read More]
696. Count Binary Substrings
One Round Solution class Solution: def countBinarySubstrings(self, s: str) -> int: """ tc O(N) sc O(1) main idea: two pointer - cnt number 0 or 1 grouped consecutively, compare current value's occurance and previous opposite value's occurance => valid number of substring is min number of consecutive 0s and 1s...
[Read More]