Skip to content

Completed s30 Trees-1#1755

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

Completed s30 Trees-1#1755
prenastro wants to merge 1 commit into
super30admin:masterfrom
prenastro:master

Conversation

@prenastro

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Validate Binary Search Tree (btfrominorderandpreorder.py)

The student appears to have submitted code for a different LeetCode problem (Construct Binary Tree from Preorder and Inorder Traversal - LeetCode #105) instead of the Validate Binary Search Tree problem (LeetCode #98).

Strengths:

  • The buildTree implementation is well-structured and follows good practices
  • Uses a hashmap for efficient lookups
  • Clear variable naming and logical flow
  • Proper handling of base cases

Areas for Improvement:

  • The student needs to solve the actual problem: Validate Binary Search Tree
  • The correct approach uses in-order traversal where the sequence must be strictly increasing
  • The reference solution demonstrates the correct approach using a prev pointer to track the previously visited node during in-order traversal

To solve the Validate BST problem, the student should implement an in-order traversal that checks if each node's value is strictly greater than the previously visited node's value.

VERDICT: NEEDS_IMPROVEMENT


Construct Binary Tree from Preorder and Inorder Traversal (validbinarysearchtree.py)

Strengths:

  • The submitted code (for BST validation) is well-structured and follows good practices
  • Clear variable naming and proper use of bounds checking
  • Good recursive base case handling
  • Includes time and space complexity analysis

Critical Issues:

  • Wrong problem entirely: The solution validates a BST, but the problem asks to construct a binary tree from preorder and inorder traversals
  • No attempt to address the actual problem requirements
  • Missing implementation for tree construction logic

To improve:

  • Carefully read the problem statement before coding
  • Understand the relationship between preorder (root-left-right) and inorder (left-root-right) traversals
  • Use hash maps for O(1) index lookup in inorder array
  • Track preorder index as you recursively build the tree

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