731. My Calendar II

```python class MyCalendarTwo: “"”tc O(N^2) sc O(N) N: number of event main idea:record historical intevals -> to get first overlaps added to overlaps record; compare if target inteval exist an overlap in overlaps inteval to check if inteval A overlaps inteval B -> A_start < B_end and A_end > B_start;... [Read More]

Lc395

```python class Solution: def longestSubstring(self, s: str, k: int) -> int: “”” tc O(26N) sc O(26) main idea: sliding window. inorder to prevent right pointer keep moving to the end, set up a stop condition — when number of unique chars (max_unique)== uniques, stop moving right pointer and start moving... [Read More]

1143. Longest Common Subsequence

Classic LCS 2D solution class Solution: def longestCommonSubsequence(self, s1: str, s2: str) -> int: """ tc O(M*N) sc O(M*N) """ m,n = len(s1), len(s2) dp = [[0] * (n+1) for _ in range(m+1)] for i in range(m): for j in range(n): if s1[i] == s2[j]: dp[i+1][j+1] = dp[i][j] + 1... [Read More]
Tags: String DP

1959. Minimum Total Space Wasted With K Resizing Operations

class Solution: def minSpaceWastedKResizing(self, nums: List[int], k: int) -> int: """tc O(N*N*K) """ @lru_cache(None) def dfs(k, cur): if cur == len(A): return 0 if k < 0 : return float('inf') maxv = 0 sum_by_i = 0 res = float('inf') for j in range(cur,len(A)): maxv = max(maxv, A[j]) sum_by_i += A[j]... [Read More]
Tags: Array DP