dsa4 min read
1D Dynamic Programming — Complete Guide
Master 1D DP: Fibonacci/Climbing Stairs, House Robber, LIS, Coin Change, Jump Game, and Kadane patterns with 5-language templates.
Read →
webcoderspeed.com
4 articles
Master 1D DP: Fibonacci/Climbing Stairs, House Robber, LIS, Coin Change, Jump Game, and Kadane patterns with 5-language templates.
Maximize amount robbed without robbing adjacent houses. Classic skip-one DP: dp[i] = max(dp[i-1], dp[i-2] + nums[i]).
Houses arranged in a circle: first and last are adjacent. Run linear House Robber twice: once excluding last house, once excluding first.
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.