Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 932 Bytes

File metadata and controls

36 lines (25 loc) · 932 Bytes

Binary Tree (validate)

Nice to solve before

Binary search tree

Instructions

Given a node, validate the binary search tree, ensuring that every node's left hand child is less than the parent node's value, and that every node's right hand child is greater than the parent

Requirements that are always true for any given node in Binary Search Tree:

  • parent node value is always greater then value of the left node and less than value of the right node
  • left node value is always less then the value of parent node
  • right node value is always greater than parent node value

challenge | solution

Examples

val tree = Node(2)
tree.insert(10)
isValidSearchBinaryTree(tree) // true

Hints

Hint 1 Use recursion
Hint 2 Pass `min` and `max` to `isValidSearchBinaryTree` method