bhargav-joshi / LearnFree

LearnFree - The Open-Source Free Learning Portal for Everyone
https://bhargav-joshi.github.io/LearnFree/index.html
13 stars 135 forks source link

Added Validate Binary Search Tree #215

Closed Ruheej1 closed 3 years ago

Ruheej1 commented 3 years ago

Ques is part of Love Babbar's 450 DSA Sheet

Check whether given tree is BST or not(as per geeksforgeeks) or Validate Binary Search Tree (on Leetcode)

Question is : Given the root of a binary tree, determine if it is a valid binary search tree (BST).

A valid BST is defined as follows:

The left subtree of a node contains only nodes with keys less than the node's key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees.

Example: input: root[2,1,3] output: true

Input: root = [5,1,4,null,null,3,6] Output: false Explanation: The root node's value is 5 but its right child's value is 4.

I want to add this question's code in CPP, kindly review the PR and add the hacktoberfest label to it. Thanks :)