Skip to content

Completed Trees 1#1752

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

Completed Trees 1#1752
sanjoli97 wants to merge 1 commit into
super30admin:masterfrom
sanjoli97:master

Conversation

@sanjoli97

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Validate Binary Search Tree (ConstructBTFromPreAndInOrderTraversal.java)

  • Major Issue: The submitted solution solves a completely different problem. Please ensure you're implementing the solution for the problem that was assigned.
  • If working on BST validation: The reference solution demonstrates the correct approach using in-order traversal with a prev pointer to track the last visited node value.
  • Key insight for BST validation: In a valid BST, an in-order traversal will produce a strictly increasing sequence. By tracking the previous node and comparing, we can validate the BST property.
  • Code quality: The code you wrote is well-structured for its intended problem (tree construction), with good use of HashMap for O(1) lookups and clear documentation.

VERDICT: NEEDS_IMPROVEMENT


Construct Binary Tree from Preorder and Inorder Traversal (ValidBST.java)

Strengths:

  • The code is clean, well-documented, and follows good coding practices
  • The BST validation logic is correctly implemented using inorder traversal
  • Proper use of early termination when flag becomes false
  • Good variable naming (flag, prev)

Critical Weakness:

  • This is the wrong problem entirely. The submission validates whether a binary tree is a valid BST, but the problem asks to construct a binary tree from preorder and inorder traversals. The student appears to have submitted code for a different LeetCode problem.

Recommendation:
The student needs to implement the correct algorithm for constructing a binary tree from preorder and inorder traversals. The reference solution shows the correct approach:

  • Use preorder's first element as the root
  • Find this root's position in inorder to divide left and right subtrees
  • Recursively build left and right subtrees
  • Use a hashmap for O(1) lookup of inorder indices

VERDICT: NEEDS_IMPROVEMENT

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