Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Advanced DP

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Advanced DP

House Robber III

advancedlayer A1 · Advanced DP5 tests

The houses of a neighbourhood form a binary tree; node.val is the money in that house. The police are alerted if you rob two houses that are directly linked — that is, a node and one of its children. Return the most money you can take.

  • A TreeNode class and a buildTree(levelOrder) helper are already provided — buildTree reads a level-order array where null marks a missing child
  • An empty tree yields 0
  • Robbing a grandchild is fine; only parent-child pairs are forbidden
  • All values are non-negative

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen