FastPrepHouse Robber with Selected Indices
Problems/House Robber with Selected Indices

House Robber with Selected Indices

Google logoGoogle● MediumINTERNNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This was a PhD intern interview. The firsthand Google internship report names the classic problem of the maximum points with no two adjacent picks. A follow-up asks for the chosen indices along with the maximum. Here we use a fixed rule that skips on ties, and the result is two rows of numbers.

Each element of points is the number of points available at one index. Choose any set of indices such that no two chosen indices are adjacent and the sum of their values is as large as possible.

Return a ragged long[][] with two rows. Row 0 contains only the maximum sum. Row 1 contains the chosen zero-based indices in increasing order.

Use this deterministic tie rule: while reconstructing from right to left using optimal prefix sums, choose index i only when taking it gives a strictly larger sum than skipping it; on equality, skip i. Choosing no index is allowed.

Function

robWithIndices(points: int[]) → long[][]

Examples

Example 1

points = [2,7,9,3,1]return = [[12],[0,2,4]]

Indices 0, 2, and 4 are non-adjacent and contribute 2 + 9 + 1 = 12.

Example 2

points = [2,2]return = [[2],[0]]

Either index gives sum 2. At index 1 taking and skipping tie, so the rule skips it and keeps index 0.

Example 3

points = [0,0,0]return = [[0],[]]

Every take decision ties with skipping, so the deterministic strategy returns the empty selection with maximum sum zero.

Constraints

  • 0 <= points.length <= 200000
  • 0 <= points[i] <= 1000000000
  • The maximum sum must be computed with signed 64-bit arithmetic.

More Google Phone Screen questions

  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
  • Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
  • Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Fewest Coins CombinationBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Longest Increasing SubsequenceByteDance · PHONE SCREENByteDance interview questions
  • Jump GamePaytm · PHONE SCREENPaytm interview questions
  • Query Words Within K PositionsPalantir · PHONE SCREENPalantir interview questions
  • House RobberVisa · PHONE SCREENVisa interview questions
  • Best Improvement Period of at Least K IntervalsAmazon · PHONE SCREEN
  • Longest Increasing SubsequenceAngel One · PHONE SCREEN
  • Maximum Product of a Contiguous SubarrayLinkedIn · PHONE SCREENLinkedIn interview questions
  • Minimum Cost for a Target WeightPace Stock Broking Services · PHONE SCREEN
  • Minimum-Cost Color SequenceOpenAI · OA · PHONE SCREENOpenAI interview questions

Interview reports that mention this question

  • Google SWE and PhD Intern Coding: 14 Experiences (Part 3 of 3)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public long[][] robWithIndices(int[] points) {
        // Write your code here.
    }
}
Checking account…