## ASU Interview Question for Accountants

Country: United States

Comment hidden because of low score. Click to expand.
2
of 4 vote

use BFS. That is. As we put node into queue, we count the number of items. Once we remove items from queue and inserts it's child, we are reaching the next level. first level we have 1 node, second level, 2, and then 4 and so on. There should be 2^i items at each level where i is the ith level.

Comment hidden because of low score. Click to expand.
0

Each node of the tree should have same height of it's left and right subtree. That solves it. If not true the method returns -1.

``````public int preOrder(Node root){
if(root==null){
return 0;
}
int lHeight = preOrder(root.getLChild());
if(lHeight == -1){
return -1;
}
int rHeight = preOrder(root.getRChild());
if(rHeight == -1){
return -1;
}
if(lHeight!=rHeight){
return -1;
}
return lHeight + 1;
}``````

Comment hidden because of low score. Click to expand.
1
of 1 vote

Number of nodes in the binary tree is 2^n-1. So just count the number of nodes in the binary tree, and return true if the count is equal to 2^n-1. where n is the height

Comment hidden because of low score. Click to expand.
0

that is great exept I have no idea what is n (n equals to..?). all I have is the tree root.

Comment hidden because of low score. Click to expand.
0

n is number of nodes in the tree

``````int height(Tree n)
{
if n == null return 0;
return max(height(n.left), height(n.right)) + 1;
}

int count(Tree n)
{
if n == null return 0;
return count(n.left) + count(n.right)) + 1;
}

bool isFullTree(Tree t)
{
int h = height(t);
int count = count(t);
return 2^h -1 == count``````

}

Comment hidden because of low score. Click to expand.
-2
of 2 vote

This logic should work:

``````bool isBinaryCompleteTree(Node* root){
if(root == NULL) return false;
if(1 && root->left == 1 && root->right)
return true;
return (isBinaryCompleteTree(root->left) && isBinaryCompleteTree(root->right));
}``````

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.