← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Meta SWE coding round with a classic dynamic programming problem. Nothing too wild, but the constraints were large enough that a naive recursive approach would've timed out.

Questions Asked (1)

Q1

Given an array of integers representing money in each house, find the maximum amount you can steal without robbing two adjacent houses.

Algorithms & Data Structures
Author's notes

Classic DP problem and I knew it the second I read it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem and constraints, then explain that this is a dynamic programming problem where for each house you decide to rob it (and add the max from two houses back) or skip it (keeping the previous max). Derive the recurrence maxRob(i) = max(maxRob(i-1), maxRob(i-2) + nums[i]) and optimize space to O(1) by keeping only the last two values.

Pro tip: After presenting the optimal solution, mention that the same pattern solves House Robber II (circular street) by splitting into two linear cases, showing you understand the underlying DP pattern rather than just memorizing one problem.

1. Clarify the problem

Restate the problem in your own words and ask clarifying questions: Can the array be empty? Are all numbers non-negative? Is the array circular? Confirm that robbing adjacent houses is forbidden.

2. Define the DP state and recurrence

Define dp[i] as the maximum amount robbable from the first i houses. Derive the recurrence: dp[i] = max(dp[i-1], dp[i-2] + nums[i]), with base cases dp[0] = 0 and dp[1] = nums[0].

3. Walk through an example

Trace the recurrence on a small example like [2,7,9,3,1] to demonstrate correctness and build intuition. Show how the decision to rob or skip each house leads to the optimal total.

4. Optimize space

Observe that dp[i] only depends on the previous two values, so replace the DP array with two variables (prev2 and prev1) to achieve O(1) space. Update them iteratively.

5. Analyze complexity and edge cases

State that the time complexity is O(n) and space is O(1). Handle edge cases: empty array returns 0, single house returns its value, two houses return the max of the two.

Key Points to Mention

  • Dynamic programming approach with optimal substructure and overlapping subproblems
  • Recurrence relation: dp[i] = max(dp[i-1], dp[i-2] + nums[i])
  • Space optimization from O(n) to O(1) using two variables
  • Time complexity O(n) and space complexity O(1)
  • Edge cases: empty array, single house, two houses
  • Extension to House Robber II (circular array) by considering two cases: rob first house or not

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.