House Robber

Asked atAmazon
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+
  1. 01Define take and skip choices at each position
  2. 02Use dp[i] = max(dp[i - 1], value[i] + dp[i - 2]) for the linear version
  3. 03Initialize empty and one-element inputs explicitly
  4. 04Compress to previous two states
  5. 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