This question is seemingly simple:
Decide if a tree is a binary tree
and then…
Decide if the tree is balanced
Another super common question you will likely be asked in one form or another. Interviewers just LOVE questions about binary tree traversal!
This question should take 30 minutes.
Some code to get you started:
//you can use an Array as a Stack or a Queue in ES6 as wellclass TreeNode{ constructor(val){ this.value = val; } addRight(val){ this.right = new TreeNode(val); return this.right; } addLeft(val){ this.left = new TreeNode(val); return this.left; }}