naveenrai8
BAN USER- 0of 0 votes
AnswersYou have to count how many binary strings are possible of length "K".
- naveenrai8 in India
Constraint: Every 0 has a 1 in its immediate left.
111011 <-- valid
0111 <--- invalid
111100 <-- invalid| Report Duplicate | Flag | PURGE
Amazon Software Engineer / Developer Algorithm
typedef struct NAryTree
{
int content;
int* children;
}tNAryTree, *tNArayTreePtr;
int sumProperty(tNArayPtr root)
{
if( root == NULL)
return 1;
int isSumPropertySatisfied = 1;
int i=0;
//iterate over all the children of this node
for(; i<n; i++)
{
//if any children is null, skip
if(root->children[i] == NULL)
continue;
isSumPropertySatisfied = isSumPropertySatisfied && sumProperty(root->children[i]);
}
return isSumPropertySatisfied;
}
please correct if i did anything wrong
- naveenrai8 June 18, 2015sum property is as follows:
For every node, value stored in it must be equal to sum of values in left and right child. Consider value as 0 for NULL children.
e.g. parent = 10, left child = 8 and right child = 2 then sum property satisfied. parent = left + right. in this case return true
e.g. parent = 10, left child = 7 and right child = 2 then sum property failed. parent != left + right. in this case return false
Do inorder traversal
perimeter of tree = (depth of first left child -1) + (no of children) + (depth of right most child -2)
depth of first left child -1: this will count the left boundary element and -1 exclude the child.
depth of right most child -2: count the elements on right boundary and -2 exclude right most child and root (root has already counted while traversing left)
Please elaborate the question. Requirement is not clear here
- naveenrai8 June 27, 2015