Validate Binary Search Tree
function validate(root){
if(!root.length){
return false;
}
if(!root[0]){
return false;
}
let currentNode = 0;
let left = 1;
let right = 2;
while(right <= root.length){
if(root[currentNode] > root[left] && root[currentNode] < root[right]){
currentNode++;
left = left + 2;
right = right + 2;
} else {
return false;
}
}
return true;
}
validate([5,1,4,34,4,3,6]);INFO