dsa1 min read
Word Break — Reachability DP
Check if string can be segmented into dictionary words. DP: dp[i]=true if some dp[j] is true and s[j:i] is in wordDict.
Read →
webcoderspeed.com
1276 articles
Check if string can be segmented into dictionary words. DP: dp[i]=true if some dp[j] is true and s[j:i] is in wordDict.
Find the length of the longest strictly increasing subsequence. O(n²) DP or O(n log n) patience sorting with binary search.
Maximum envelopes you can nest. Sort by width ascending and height descending, then LIS on heights. Descending heights prevents using same-width twice.
Count palindromic substrings. Expand around each center (n odd-length + n-1 even-length centers), count valid expansions.
Find longest palindromic subsequence length. 2D DP: if s[i]==s[j], dp[i][j] = dp[i+1][j-1]+2, else max of neighbors. Fill diagonally.