House Robber II

Reported by candidates from Kotak Mahindra Bank's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Kotak Mahindra Bank OA. Under 2s to a working solution.
Founder's read

The Kotak Mahindra Bank OA reported in September 2026 hides its trap in a single-house array. House Robber II looks like the classic linear DP until you notice the street is a circle, so the first and last houses can't both be robbed. Skip that detail and your answer fails on [2,3,2]. It's a dynamic programming problem with one twist, and the twist takes about five minutes to fix once you see it. If you blank mid-assessment, StealthCoder runs invisibly as a safety net and hands you the solution while the proctor sees nothing.

The problem

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[]) → int

Examples
Example 1
nums = [2,3,2]
return = 3
The two houses worth 2 are adjacent around the circle, so choose the middle house worth 3.
Example 2
nums = [1,2,3,1]
return = 4
Choose values 1 and 3 at indices 0 and 2; they are not adjacent.
Example 3
nums = [5]
return = 5
The 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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to break the circle into two linear problems. Either you skip the first house or you skip the last, because you can't take both. So run the standard House Robber DP on nums[0..n-2] and again on nums[1..n-1], then return the max of the two. The linear DP keeps two variables: prev and curr, where the new value is max(curr, prev + num). That's O(n) time and O(1) space, which handles n up to 10^5 easily. The pitfall is n equals 1. Both slices come out empty, so you return 0 and fail Example 3. Special-case it and return nums[0] directly. Zeros are fine since selecting nothing is allowed. If the edge case slips past you during the live OA, StealthCoder is the hedge that surfaces the two-pass structure and the n==1 guard.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill House Robber II cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as house robber ii. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Kotak Mahindra Bank's OA.

Kotak Mahindra Bank reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

House Robber II FAQ

How hard is House Robber II really?+

Medium. If you know linear House Robber, this is one small step up. The only new idea is splitting the circle into two ranges. Most candidates who fail it forget the single-house case rather than the DP itself.

What's the trick for the circular constraint?+

The first and last houses are adjacent, so at most one of them is robbed. Solve the linear problem twice, once excluding the first house and once excluding the last, then take the larger result. That covers every valid selection.

What edge case breaks a naive solution here?+

A single house. Slicing nums[0..n-2] and nums[1..n-1] gives two empty ranges and returns 0, but the answer is nums[0]. Add an early return when the length is 1. Example 3 tests exactly this.

What time and space complexity should I aim for?+

O(n) time and O(1) space. Two passes of the rolling-variable DP, no array needed. With n up to 10^5, anything quadratic or exponential like plain recursion without memoization will time out, so avoid it.

How do I prepare for this in 48 hours?+

Write linear House Robber from memory first, using two rolling variables. Then wrap it in a helper that takes a range and call it twice. Test on [2,3,2], [1,2,3,1], and [5]. That's the whole problem, and it's a one-hour job.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Kotak Mahindra Bank.

OA at Kotak Mahindra Bank?
Invisible during screen share
Get it