Count Number of Ways to Place Houses
A medium-tier problem at 43% community acceptance, tagged with Dynamic Programming. Reported in interviews at Nagarro and 0 others.
You've got a row of plots, and you need to count valid ways to place houses such that no two adjacent plots have houses. This is a classic DP constraint problem that looks simple but catches candidates who jump straight to brute force. Nagarro has asked it. The acceptance rate sits at 43%, which means nearly 6 in 10 candidates stumble. Most fail because they either miss the constraint entirely or write an exponential solution when linear DP solves it cold. If this problem hits your live OA and you blank on the state transitions, StealthCoder surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Count Number of Ways to Place Houses"
Count Number of Ways to Place Houses is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe trick is recognizing this as a state machine problem, not a permutation problem. You build a DP array where each position tracks two states: house placed or house not placed. At each plot, you either place a house (which means the previous plot must be empty) or skip it (which means the previous can be anything). The recurrence is straightforward: ways[i] = ways[i-1] + ways[i-2], but only if you track the constraint correctly through your state definition. Candidates usually mess up by not separating the two states or by conflating the constraint. Once you see it as 'empty or filled at position i', the solution is linear time and constant space. StealthCoder is the hedge if the framing doesn't click during the live assessment and you need a working implementation fast.
Pattern tags
You know the problem.
Make sure you actually pass it.
Count Number of Ways to Place Houses recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Number of Ways to Place Houses interview FAQ
Is this really just Fibonacci with extra steps?+
Functionally, yes, but the problem is testing whether you can translate a constraint into state transitions. The recurrence emerges from the rule 'no adjacent houses', not from the problem asking for Fibonacci directly. That translation step is where most candidates miss the pattern.
Why is the acceptance rate so low if the solution is simple?+
Because 'simple' and 'obvious during an interview' are different things. Candidates either overthink the constraint and write buggy state logic, or they code a recursive brute force and run out of time. The DP framing isn't hard once you see it, but seeing it under pressure is the real test.
What's the most common mistake?+
Forgetting to track both states (house and no house) separately, or mixing up the base cases. Some candidates also incorrectly apply the constraint, treating it as 'at most one house per two plots' instead of 'no two adjacent'. The constraint is strict adjacency.
Does Nagarro ask follow-ups after this?+
Unknown from public data, but if they do, expect modifications like 'houses have different colors' or 'some plots are blocked'. The core DP skeleton remains the same. Once you nail the state transitions, variations are usually just extra constraints bolted on.
Is this still being asked if I prepare for FAANG first?+
Nagarro isn't a FAANG company, so it's lower frequency on most prep curricula. That's actually why you should know it. Problems asked outside the big five are often skipped by prep-focused candidates, which makes them effective filter questions.
Want the actual problem statement? View "Count Number of Ways to Place Houses" on LeetCode →