Skip to content

Files

Latest commit

2c30ef9 · Jul 24, 2023

History

History
This branch is 7 commits ahead of, 10 commits behind igorwojda/kotlin-coding-challenges:main.

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 20, 2023
Jul 24, 2023
Mar 1, 2023

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 than value of all nodes in the left subtree
    and less than value of all nodes in the right subtree
  • left node value is also a valid BST
  • right node value is also a valid BST

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