LC238. Product of Array Except Self

class Solution: def productExceptSelf(self, A: List[int]) -> List[int]: """ tc O(N) sc O(N) use two seperate array to cache current item in Array A's left range and right range 's accumutive product loop through the index get the combined range product res for current index L[i]: for A[i], its left... [Read More]
Tags: Array

LC378. Kth Smallest Element in a Sorted Matrix

Heap Solution ```python class Solution: def kthSmallest(self, matrix: List[List[int]], k: int) -> int: # time O(NlgN) space O(1) n = len(matrix) lo = matrix[0][0] hi = matrix[-1][-1] cnt,candi = 0,0 while lo < hi: mid = lo + (hi-lo)//2 cnt,candi = self.cnt_less_equal(matrix,mid) #print(cnt,candi,"aaaaaaaaaa") # before mid, # of valuse <... [Read More]

LC209. Minimum Size Subarray Sum

```python class Solution: def minSubArrayLen(self, s: int, nums: List[int]) -> int: “”” sliding window, 2 loops 1. initialize left ptr, right ptr local sum 2. loop array, get accumutive local sum 3. when local sum >= s, move left ptr and compare with global min size (ans) 4. check if... [Read More]

LC134. Gas Station

class Solution: def canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int: """ time O(N) space O(1) 1. loop through gas, cost array, get total gas, total cost 2. during iteration, check current tank < 0, if yes, reset current tank, start from i + 1 3. check if total cost <=... [Read More]
Tags: Greedy