213. House Robber II

```python time O(N) space O(1) ””” main idea: choose 1st element means last one can not be choosen. not chooen 1st element means last element can be an option to choose( not determined)=> valid loop range will be correspondinglly [0,len(nums)-1] and [1,len(nums)-2].since loop range differs, we need to discuss in... [Read More]
Tags: DP

11. Container With Most Water

```python class Solution: def maxArea(self, height: List[int]) -> int: # time O(N) space O(1) “”” main idea: two pointers, change the pointer with shorter height “”” l, r = 0, len(height)-1 max_w = 0 while l <r: h =min(height[l],height[r]) max_w = max(max_w,h*(r-l)) if height[l] <height[r]: l += 1 else: r... [Read More]

72. Edit Distance

Top-down Solution ```python class Solution: def minDistance(self, word1: str, word2: str) -> int: m,n = len(word1), len(word2) # edge case: if not word1 or not word2: return m + n # create memo cache = [[-1]*(n) for _ in range(m)] return self.match(word1,word2,0,0,cache) #return memo[-1][-1] def match(self,w1,w2,i,j,memo): # termination conditions: 3... [Read More]
Tags: String DP

148. Sort List

```python Definition for singly-linked list. class ListNode: def init(self, val=0, next=None): self.val = val self.next = next class Solution: # time O(NlgN) space O(lgN) [Read More]
Tags: Tree Design