House Robber II
Updated
Problem statement
Given an integer array nums, where nums[i] is the money in house i, return the most money you can rob. The houses stand in a circle, so the first and last houses are neighbors. You cannot rob two neighboring houses, or an alarm goes off.
You may skip every house. If there is only one house, you may rob it.
Function
robCircular(nums: int[]) → intExamples
Example 1
nums = [2,3,2]return = 3The first and last houses each hold two, but they are neighbors around the circle. Robbing only the middle house gives three, the best total.
Example 2
nums = [1,2,3,1]return = 4Rob the first house (one) and the third house (three). They are not neighbors, so the total is four.
Example 3
nums = [0]return = 0The only house holds no money, so the answer is zero.
Constraints
1 <= nums.length <= 10^5.0 <= nums[i] <= 10^4.
More Apple interview questions
- Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Merge Two Strings by Maximum Boundary OverlapOA · Seen Sep 2026
- Collect Letters Along a Unique Grid PathOA · Seen Aug 2025
- Maximum Weight in Two BagsOA · Seen Aug 2025
- Ignore SectionsOA · Seen Mar 2024
- Gas Station Circular TourOA · Seen Nov 2021
- Clone an Undirected Graph StateOA · Seen Mar 2021
- Longest Increasing Subsequence LengthOA · Seen Feb 2021
- Maximum Later DifferenceOA · Seen Feb 2021
- Topological OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Card Game: Best First-Player ScoreShopify · OAShopify interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- 0/1 KnapsackConfluent · OAConfluent interview questions
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft 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