Skip to content
Katabench
Try free

House Robber

Easy About 10 min Free, no account needed

Maximize the loot without robbing two adjacent houses.

The brief

Given nums, the loot in each house along a street, return the maximum sum you can rob without ever robbing two adjacent houses.

The performance bar

The obvious approach recurses on "rob this house or skip it": 2^n paths. The hidden street has 200,000 houses, so that's far too slow. Aim for O(n).

Starter code

C#
using System;

public class Solution
{
    // TODO: return the maximum loot with no two adjacent houses robbed.
    public long Rob(int[] nums)
    {
        throw new NotImplementedException();
    }
}

How it is graded

Visible examples help you iterate. Hidden tests then cover edge cases and larger inputs, and every test reports server-measured time and allocated bytes.

C# coding challenges →

What it practices

Dynamic programming
Define subproblems and a recurrence, then reuse solved subproblems instead of recomputing them.

Related katas