Tell us what’s happening:
Hi, guys! Found a bag in Find the Minimum and Maximum Height of a Binary Search Tree. You can pass all the test with just an empty isBalanced function.
Your code so far
function Node(value) {
this.value = value;
this.left = null;
this.right = null;
}
function BinarySearchTree() {
this.root = null;
this.findMinHeight = (root=this.root) => {
if (root === null) return -1;
if (root.left === null && root.right === null) return 0;
if (root.left === null) return this.findMinHeight(root.right) + 1;
if (root.right === null) return this.findMinHeight(root.left) + 1;
const leftHeight = this.findMinHeight(root.left) + 1;
const rightHeight = this.findMinHeight(root.right) + 1;
return Math.min(leftHeight, rightHeight);
}
this.findMaxHeight = (root=this.root) => {
if (root === null) return -1;
if (root.left === null && root.right === null) return 0;
if (root.left === null) return this.findMaxHeight(root.right) + 1;
if (root.right === null) return this.findMaxHeight(root.left) + 1;
const leftHeight = this.findMaxHeight(root.left) + 1;
const rightHeight = this.findMaxHeight(root.right) + 1;
return Math.max(leftHeight, rightHeight);
}
this.isBalanced = () => {
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0
.
Challenge: Find the Minimum and Maximum Height of a Binary Search Tree
Link to the challenge: