Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implemented LeetCode Problem #337 - House Robber III in C++ using Tree DP #3034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
darshkantaria wants to merge 1 commit into TheAlgorithms:master
base: master
Choose a base branch
Loading
from darshkantaria:patch-2

Conversation

@darshkantaria
Copy link

@darshkantaria darshkantaria commented Oct 10, 2025

This PR adds a C++ solution for LeetCode Problem #337 - House Robber III

  • Approach: Dynamic Programming (Tree DP) using Post-order DFS

  • Each node computes two states:

    1. Rob this node → cannot rob its children
    2. Skip this node → free to rob or skip children
  • Time Complexity: O(n), where n = number of nodes

  • Space Complexity: O(h), where h = height of the tree

The code includes detailed inline comments and explanation of the approach,
making it easy to understand and reusable for similar tree DP problems.

Optional test case is included but commented out for safe submission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Panquesito7 Panquesito7 Awaiting requested review from Panquesito7 Panquesito7 is a code owner

@realstealthninja realstealthninja Awaiting requested review from realstealthninja realstealthninja is a code owner

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /