dsa1 min read
Delete and Earn — House Robber on Frequency Array
Picking value k deletes all k-1 and k+1 elements. Map to House Robber: earn[k] = k * count(k), then max non-adjacent sum.
Read →
1575 articles
Picking value k deletes all k-1 and k+1 elements. Map to House Robber: earn[k] = k * count(k), then max non-adjacent sum.
Find the contiguous subarray with the largest sum. Kadane's algorithm: either extend previous subarray or start fresh at current element.
Find maximum product of a contiguous subarray. Track both min and max at each position because a negative * negative becomes positive.
Find minimum coins to make amount. Unbounded knapsack DP: dp[amount] = min(dp[amount-coin]+1) over all coins. Bottom-up from 0 to amount.
Count number of combinations making up amount. Process each coin denomination completely (outer loop = coin) to avoid counting permutations.