FastPrepHouse Robber
Problems/House Robber

House Robber

Headlands Technologies logoHeadlands Technologies● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The onsite report names House Robber. This exercise brings back that exact task of houses in a line, and its numeric limits, from the main reference. The function package and the implementations are our adaptations, since the original interview code was not given. Our version is about 90% the same as the reported question.

nums[i] is the amount available at position i along a linear street. Choose positions with the largest possible total amount. You cannot choose two positions next to each other.

Return the maximum total as an integer. You may select no positions, giving 0. The first and last positions are adjacent only when they are consecutive indices; the street is not circular. Return the value only, not a list of selected indices. Do not modify nums.

Function

rob(nums: int[]) → int

Examples

Example 1

nums = [1,2,3,1]return = 4

Choose the first and third entries: 1 + 3 = 4.

Example 2

nums = [2,7,9,3,1]return = 12

Choose positions 0, 2 and 4: 2 + 9 + 1 = 12.

Example 3

nums = [2,1,1,2]return = 4

Choosing the first and last entries gives 4; picking only one index parity would miss this combination.

Constraints

  • 1 <= nums.length <= 100.
  • 0 <= nums[i] <= 400.
  • At most 50 positions can be selected, so the result is at most 20000 and fits a signed 32-bit integer.

More Headlands Technologies interview questions

  • As-Of JoinOA · ONSITE INTERVIEW · Seen Aug 2026
  • Triggered Order Event FilterONSITE INTERVIEW · Seen Oct 2024
  • Best Time to Buy and Sell StockPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2024
  • Best Time to Buy and Sell Stock IIONSITE INTERVIEW · Seen Apr 2024
  • Merge IntervalsONSITE INTERVIEW · Seen Apr 2024
  • Net Position Calculation from API SnapshotsONSITE INTERVIEW · Seen Apr 2024
  • Disaster RecoveryOA · Seen Nov 2026
  • Integer Compression OffsetPHONE SCREEN · Seen Oct 2026
  • Array Interval SumsOA · Seen Oct 2026
  • Job Runner Chain ReportsOA · Seen Oct 2026

Similar questions at other companies

  • Assign Escalations to TeamsAmazon · ONSITE INTERVIEW
  • Distinct Subset SumsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Count Subsets With a Target SumSafe Security · ONSITE INTERVIEW
  • Maximum Subarray Sum with One DeletionOracle · ONSITE INTERVIEWOracle interview questions
  • Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Coin ChangeMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Maximum SubarrayUpstart · ONSITE INTERVIEWUpstart interview questions
  • Smallest Sufficient TeamExpedia · ONSITE INTERVIEWExpedia interview questions
  • Maximum Product SubarrayHartford Financial Services · ONSITE INTERVIEWHartford Financial Services interview questions
  • Word BreakMoveworks · ONSITE INTERVIEWMoveworks interview questions
All Headlands Technologies interview questionsSee Headlands Technologies hiring insights
Saved
class Solution {
    public int rob(int[] nums) {
        // write your code here
    }
}
Checking account…