## Given a complete binary tree find if it is a value balanced tree or not.

C++ solution

```
bool isValueBalancedTree(size_t count, int *tree)
{
int leftSum = 0, rightSum = 0;
size_t n;
tree++; // First tree item [0] can be ignored
count--;
for (int halfElementsThisRow = 1; count; halfElementsThisRow *= 2, count -= halfElementsThisRow)
{
for (n = halfElementsThisRow; n--; )
leftSum += *tree++;
for (n = halfElementsThisRow; n--; )
rightSum += *tree++;
}
return leftSum == rightSum;
}
```

Sale Aricent ka q khud kar le.lodu

- Chutiye July 11, 2015