BBlinkit·DSASDE-1DSA Phone Screen
Solve the House Robber problem
Given an array of non-negative integers representing the amount of money in each house, find the maximum amount you can rob without robbing two adjacent houses.
Approach progression expected:
- Brute-force recursion → memoization (top-down DP) → tabulation (bottom-up DP) → space-optimized O(1) DP
State transition: dp[i] = max(dp[i-1], dp[i-2] + nums[i]) — either skip the current house or rob it plus the best up to two houses back.
Complexity: O(n) time, O(1) space in the optimized form (track only the previous two values).
Variations: House Robber II (circular array), House Robber III (binary tree), or generalizing to a k-step gap constraint.
added 11h ago