House Robber II
Updated
Problem statement
Houses stand in a circle. The nonnegative integer nums[i] is the value available in house i. Select houses with no two adjacent and return the maximum total value.
The first and last houses are adjacent. For this exercise, assume there is at least one house, selecting none is allowed, and a single house may be selected.
Function
robCircular(nums: int[]) → intExamples
Example 1
nums = [2,3,2]return = 3The two houses worth 2 are adjacent around the circle, so choose the middle house worth 3.
Example 2
nums = [1,2,3,1]return = 4Choose values 1 and 3 at indices 0 and 2; they are not adjacent.
Example 3
nums = [5]return = 5The only house may be selected.
Constraints
1 <= nums.length <= 10^5.0 <= nums[i] <= 10^4.- The result fits in a signed 32-bit integer.
More Navan interview questions
- Roman to IntegerPHONE SCREEN · Seen Oct 2024
- Sort ColorsPHONE SCREEN · Seen Oct 2024
- Basic CalculatorPHONE SCREEN · Seen Jun 2024
- LRU CachePHONE SCREEN · Seen Jun 2024
- House RobberPHONE SCREEN · Seen May 2024
- Snake-Case Iterator to Camel CasePHONE SCREEN · Seen Feb 2024
- Lexicographically Largest Distinct-Letter SubsequencePHONE SCREEN · Seen May 2023
- Time Based Key-Value StoreONSITE INTERVIEW · Seen Dec 2025
- Type-Ahead Prefix MatchesONSITE INTERVIEW · Seen Dec 2024
- Minimum Steps on a Circular Character DialONSITE INTERVIEW · Seen Jan 2024
Similar questions at other companies
- Maximum Subarray Sum with One DeletionServiceNow · PHONE SCREENServiceNow interview questions
- Maximum Product of a Contiguous SubarrayLinkedIn · PHONE SCREENLinkedIn interview questions
- 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
- Match Shops and BuyersGoogle · PHONE SCREENGoogle interview questions