Skip to content

Completed Trees-1#1722

Open
sreevardhan1099 wants to merge 1 commit intosuper30admin:masterfrom
sreevardhan1099:master
Open

Completed Trees-1#1722
sreevardhan1099 wants to merge 1 commit intosuper30admin:masterfrom
sreevardhan1099:master

Conversation

@sreevardhan1099
Copy link
Copy Markdown

@sreevardhan1099 sreevardhan1099 changed the title Complete Trees-1 Completed Trees-1 Jan 26, 2026
@super30admin
Copy link
Copy Markdown
Owner

Great job on both solutions! Your code is clean, efficient, and follows best practices.

For Problem-1.py (Validate BST):

  • Your use of in-order traversal with a global prev variable is a classic and efficient approach. The conditional recursion to break early when the BST condition is violated is a nice touch that improves efficiency in worst-case scenarios.
  • One minor suggestion: In Python, it's common to use None for comparisons rather than is not None. Your code already does this correctly, so keep it up.

For Problem-2.py (Construct Binary Tree from Preorder and Inorder Traversal):

  • Your solution is well-optimized with the dictionary for O(1) lookups of indices in the inorder list. The recursive helper function is implemented correctly.
  • You might consider adding error handling or checks for empty input, but the problem constraints assume non-empty trees, so it's not strictly necessary.

Both solutions demonstrate a strong understanding of tree traversals and recursion. Continue to write clear comments and maintain this level of code quality.

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