Skip to content

trees-1#1751

Open
joshyoon92 wants to merge 2 commits into
super30admin:masterfrom
joshyoon92:master
Open

trees-1#1751
joshyoon92 wants to merge 2 commits into
super30admin:masterfrom
joshyoon92:master

Conversation

@joshyoon92

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Validate Binary Search Tree (ValidateBST.java)

Strengths:

  • Clean, well-structured recursive solution
  • Correct use of min/max bounds approach
  • Good variable naming and code organization
  • Handles edge cases properly (null checks)

Areas for Improvement:

  • Consider adding early termination after flag becomes false to avoid unnecessary recursive calls
  • Could add a check at the start of helper to return immediately if flag is already false

Minor suggestions:

  • The code could benefit from a comment explaining the min/max bounds logic for future readers

VERDICT: PASS


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

Strengths:

  • Clean variable naming (sum, currSum)
  • Good base case handling (null check)
  • Proper use of helper method with accumulated sum
  • Correct leaf node detection (both children null)

Critical Issues:

  1. Wrong Problem: This solution solves "Sum Root to Leaf Numbers" (LeetCode 129), not "Construct Binary Tree from Preorder and Inorder Traversal" (LeetCode 105). The problem requires building a tree from two traversal arrays.

  2. Missing Tree Construction Logic: The solution needs to:

    • Use the preorder array to identify root values
    • Use the inorder array to determine left/right subtree boundaries
    • Build TreeNode objects recursively
  3. Return Type Mismatch: The problem requires returning a TreeNode* (or TreeNode in Java), but this solution returns an int.

To Fix:

  • Remove the sum logic entirely
  • Implement a recursive approach using preorder index tracking
  • Use a HashMap for inorder value-to-index mapping
  • Build left and right subtrees recursively based on inorder boundaries

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