Skip to content

Solved Trees-2#1575

Open
pratul2789 wants to merge 1 commit into
super30admin:masterfrom
pratul2789:master
Open

Solved Trees-2#1575
pratul2789 wants to merge 1 commit into
super30admin:masterfrom
pratul2789:master

Conversation

@pratul2789
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Your solution for constructing the binary tree from inorder and postorder traversals is correct and efficient. You have correctly implemented the recursive approach using a hashmap for index lookup, and you are building the right subtree before the left subtree, which is crucial because the postorder traversal gives the root last and the previous element is the root of the right subtree.

Strengths:

  • You used a dictionary to store inorder indices, which allows for O(1) lookups.
  • The recursion is handled correctly with base cases.
  • The code is clean and well-commented.

Areas for improvement:

  • The variable name treeRootIdx might be improved to something more descriptive like post_index or current_post_index to clearly indicate that it tracks the current position in the postorder array.
  • You should ensure that you are only submitting the solution for the problem at hand. The inclusion of the "SumRootToLeafNumbers" solution in the same submission is unnecessary and might be confusing. In a real scenario, you would only submit the solution for the problem you are solving.

Overall, your solution for the correct problem is excellent.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants