← All questions
MediumCoding
House Robber II
Asked at
Acko
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
- 01Define take and skip choices at each position
- 02Use dp[i] = max(dp[i - 1], value[i] + dp[i - 2]) for the linear version
- 03Initialize empty and one-element inputs explicitly
- 04Compress to previous two states
- 05For the circular version, solve the two cases excluding first or last and take the better answer
Reference answer
Then expect these follow-ups
What constraint would change your chosen approach?
Tests: constraint adaptation
How would you test the edge cases before implementation?
Tests: implementation extension
Free to read · better with Enzo
Practice this out loud with Enzo
Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.
Next question