Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

At each house: either rob it (must have skipped previous) or skip it.

Approach

Maintain:

  • take = best if we rob current house
  • skip = best if we skip current house Update per value x: newTake = skip + x, newSkip = max(skip, take).
Code
Loading...
Complexity
Time: O(n)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

At each house: either rob it (must have skipped previous) or skip it.

Approach

Maintain:

  • take = best if we rob current house
  • skip = best if we skip current house Update per value x: newTake = skip + x, newSkip = max(skip, take).
Code
Loading...
Complexity
Time: O(n)
Space: O(1)