Answer: Paytm OA Question 2024 June | Dynamic Programming | on-campus

Answer · Posted Jun 2026

Solution: House Robber — Space Optimized Dynamic Programming Approach We use Dynamic Programming. At each house, we have two choices: rob it or skip it. If we rob house i: we add nums[i] to the best amount from two houses ago (dp[i-2]). If we skip house i: we carry forward the best amount from the previous house (dp[i-1]). So: dp[i] = max(dp[i-1], dp[i-2] + nums[i]) We optimize space to O(1) by only tracking the previous two values instead of a ...

The full answer & interview discussion are available to premium members.

Log in Create a free account