FastPrepHouse Robber
Problems/House Robber

House Robber

Salesforce logoSalesforce● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Salesforce onsite interview. The report names House Robber and a dynamic-programming solution. It does not give the function signature, examples or limits. We added those. Our version is about 94% the same as the reported question.

You are given an array nums where nums[i] is the amount available in house i. The houses form one line.

Select houses to maximize the total amount, subject to the rule that two adjacent houses cannot both be selected. Return the maximum total amount.

Function

rob(nums: int[]) → int

Examples

Example 1

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

Select houses 0 and 2 for a total of 1 + 3 = 4.

Example 2

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

Select houses 0, 2, and 4 for a total of 12.

Example 3

nums = [5]return = 5

The only house can be selected.

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^4
  • The maximum total fits in a signed 32-bit integer.

More Salesforce Onsite Interview questions

  • Count Increasing TripletsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Reverse a Sublist of a Linked ListONSITE INTERVIEW · Seen Nov 2026
  • Rotting OrangesONSITE INTERVIEW · Seen Nov 2026
  • 3Sum SmallerONSITE INTERVIEW · Seen Nov 2026
  • Count Zero Request ServersONSITE INTERVIEW · Seen Nov 2026
  • Group Identical Tree LevelsONSITE INTERVIEW · Seen Oct 2026
  • Meeting Rooms IIONSITE INTERVIEW · Seen Oct 2026
  • Construct a Tree from Level-Order and Inorder TraversalsONSITE INTERVIEW · Seen Sep 2026
  • Maximize Monsters DefeatedONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Maximum Sum with K-Element SkippingPhonePe · ONSITE INTERVIEWPhonePe interview questions
  • 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

Salesforce interview experiences

  • Salesforce Infrastructure SWE OA and Onsite: 1 Experience
  • Salesforce Experienced Backend SWE First Round: 1 Experience
All Salesforce interview questionsSee Salesforce hiring insights
Saved
class Solution {
    public int rob(int[] nums) {
        // write your code here
    }
}
Checking account…