Complete Trees-1 assignment - #1757
Conversation
Validate Binary Search Tree (BinaryTreePreOrderInOrderTraversal.java)The student has submitted a solution for a completely different problem (Binary Tree Construction from Preorder and Inorder Traversal) instead of the Validate Binary Search Tree problem. While the code itself appears to be a reasonable solution for the problem it was intended for, it does not address the actual problem at hand. To correctly solve the Validate Binary Search Tree problem, you should:
Here's a sketch of the in-order traversal approach: class Solution {
TreeNode prev;
public boolean isValidBST(TreeNode root) {
if (root == null) return true;
// Check left subtree
if (!isValidBST(root.left)) return false;
// Check current node
if (prev != null && prev.val >= root.val) return false;
prev = root;
// Check right subtree
return isValidBST(root.right);
}
}VERDICT: NEEDS_IMPROVEMENT Construct Binary Tree from Preorder and Inorder Traversal (ValidBST.java)It appears you have submitted a solution for a different problem (Validate Binary Search Tree) instead of the required problem (Construct Binary Tree from Preorder and Inorder Traversal). To solve the correct problem, you need to:
Please re-submit with the correct solution for the given problem. VERDICT: NEEDS_IMPROVEMENT |
No description provided.