FastPrepHouse Robber
Problems/House Robber

House Robber

Microsoft logoMicrosoft● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A 2025 on-campus Microsoft internship online assessment had two coding questions. The candidate described the first one only as similar to the House Robber problem. The report does not say how the assessment version changed it, so this page uses the standard House Robber task. Pick houses from a row so that no two picked houses are next to each other, and return the largest total.

The size limits are our choice: up to 10^5 houses, each holding 0 to 10^4.

Our version is about 60% the same as the reported question.

You are planning to rob houses along a street. The houses stand in a row, and nums[i] is the amount of money in house i.

Neighboring houses share an alarm system: if two houses that are next to each other are both robbed, the alarm goes off. So you may rob any set of houses as long as no two of them are adjacent. You may skip as many houses in a row as you like.

Return the largest total amount of money you can rob without setting off the alarm.

Function

rob(nums: int[]) → int

Examples

Example 1

nums = [4,1,2,7,5,3,1]return = 14

Rob houses 0, 3 and 5 for 4 + 7 + 3 = 14. No two of them are next to each other.

Taking every other house does worse: houses 0, 2, 4 and 6 give 4 + 2 + 5 + 1 = 12, and houses 1, 3 and 5 give 1 + 7 + 3 = 11.

Example 2

nums = [2,9,3]return = 9

Houses 0 and 2 are not neighbors and give 2 + 3 = 5. Robbing house 1 alone gives 9, which is more. House 1 is next to both other houses, so nothing can be added to it.

Example 3

nums = [6,0,0,6]return = 12

Rob the first and the last house for 6 + 6 = 12. The two houses in between are skipped together, which is allowed: you may skip more than one house in a row.

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^4

More Microsoft Online Assessment questions

  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026
  • Maximum Sum of a K-StarOA · Seen Oct 2026
  • Capacity to Ship Packages Within DaysOA · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • 0/1 KnapsackConfluent · OAConfluent interview questions
  • Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
  • Maximum Subarray SumStraive · OA
  • Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
  • Lowest-Cost Shirt Color ScheduleElevenLabs · OAElevenLabs interview questions
  • Maximum Game Board ScoreJP Morgan Chase · OAJP Morgan Chase interview questions
  • API Bandwidth AllocationArista Networks · OAArista Networks interview questions
  • Maximum Points by Deleting ElementsIBM · OAIBM interview questions
  • House RobberWalmart · OAWalmart interview questions
  • Three-Resource 0/1 KnapsackMorgan Stanley · OAMorgan Stanley interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int rob(int[] nums) {
        // Write your code here.
    }
}
Checking account…