Problem
Ask
Submissions

Problem: House Robber III

Medium
30 min
Understand how to apply backtracking to solve the House Robber III problem by selecting nodes in a binary tree that maximize stolen money without robbing adjacent houses. Learn to analyze the problem constraints, develop a recursive approach, and implement an efficient solution that prevents police alerts while maximizing profits.

Statement

A thief has discovered a new neighborhood to target, where the houses can be represented as nodes in a binary tree. The money in the house is the data of the respective node. The thief can enter the neighborhood from a house represented as root of the binary tree. Each house has only one parent house. The thief knows that if he robs two houses that are directly connected, the police will be notified. The thief wants to know the maximum amount of money he can steal from the houses without getting caught by the police. The thief needs your help determining the maximum amount of money he can rob without alerting the police.

Constraints:

  • The number of nodes in the tree is in the range [1,500][1, 500].
  • 00 \leq node.data 104\leq 10^4
Problem
Ask
Submissions

Problem: House Robber III

Medium
30 min
Understand how to apply backtracking to solve the House Robber III problem by selecting nodes in a binary tree that maximize stolen money without robbing adjacent houses. Learn to analyze the problem constraints, develop a recursive approach, and implement an efficient solution that prevents police alerts while maximizing profits.

Statement

A thief has discovered a new neighborhood to target, where the houses can be represented as nodes in a binary tree. The money in the house is the data of the respective node. The thief can enter the neighborhood from a house represented as root of the binary tree. Each house has only one parent house. The thief knows that if he robs two houses that are directly connected, the police will be notified. The thief wants to know the maximum amount of money he can steal from the houses without getting caught by the police. The thief needs your help determining the maximum amount of money he can rob without alerting the police.

Constraints:

  • The number of nodes in the tree is in the range [1,500][1, 500].
  • 00 \leq node.data 104\leq 10^4