```python
time O(R*C) space O(1) ignoring depth of stack
class Solution:
def maxAreaOfIsland(self, grid: List[List[int]]) -> int:
max_a = 0
rows = len(grid)
cols = len(grid[0])
for i in range(rows):
for j in range(cols):
if grid[i][j] == 1:
cnt = self.dfs(i,j,grid)
max_a = max(cnt,max_a)
return max_a
[Read More]
377. Combination Sum IV
Top down way/Memoization
[Read More]
215. Kth Largest Element in an Array
Heaq sort time O(NlgK) space O(K) K = heap size from heapq import heappop, heappush class Solution: def findKthLargest(self, nums: List[int], k: int) -> int: hp = [] res = 0 n = len(nums) target = n-k+1 for num in nums: heappush(hp,-num) if len(hp) > target: heappop(hp) res = heappop(hp)...
[Read More]
75. Sort Colors
```python
class Solution:
def sortColors(self, nums: List[int]) -> None:
“””
Do not return anything, modify nums in-place instead.
time O(N) space O(1)
[0,zero) = 0
[zero,i) = 1
[two,len-1] = 2, two = len-1
"""
# step1: edge case
size = len(nums)
if size < 2 :
return
[Read More]
215. Kth Largest Element in an Array
Binary Heap solution from heapq import heappop, heappush class Solution: # time O(NlgK) space O(K) K = heap size def findKthLargest(self, nums: List[int], k: int) -> int: hp = [] res = 0 n = len(nums) target = n-k+1 for num in nums: heappush(hp,-num) if len(hp) > target: heappop(hp) res...
[Read More]