Maximize a Nonadjacent Selection around a Circle

Quick Overview

Maximize a circular nonadjacent house-selection sum by solving two endpoint-excluding line intervals.

Maximize a Nonadjacent Selection around a Circle

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Select nonadjacent houses to maximize the collected total when the houses form a circle. The first and last houses are neighbors, so they cannot both be selected when there is more than one house. Return the maximum total. ```cpp int rob(vector<int>& nums); ``` ### Examples ```text Input: nums = [6,1,2,7] Output: 8 ``` Choose amounts 6 and 2, or amounts 1 and 7. ```text Input: nums = [8] Output: 8 ``` ### Constraints - Length is between 1 and 100. - Each amount is between 0 and 1000. - Adjacent houses cannot both be selected.

Overview: Maximize a circular nonadjacent house-selection sum by solving two endpoint-excluding line intervals.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Select nonadjacent houses to maximize the collected total when the houses form a circle. The first and last houses are neighbors, so they cannot both be selected when there is more than one house. Return the maximum total.

int rob(vector<int>& nums);

Examples

Input: nums = [6,1,2,7]
Output: 8

Choose amounts 6 and 2, or amounts 1 and 7.

Input: nums = [8]
Output: 8

Constraints

  • Length is between 1 and 100.
  • Each amount is between 0 and 1000.
  • Adjacent houses cannot both be selected.