Leaderboard
Showing:
Count the Number of Full Binary Trees
Medium Accuracy: 0.0% Submissions: 9 Points: 4

Given an array A[] of N integers, where each integer is greater than 1.The task is to find the number of Full binary tree from the given integers, such that each non leaf node value is the product of its children value.

Note: Each integer can be used multiple times in a full binary tree. 

Example 1:
Input:
N = 4
A[] = {2, 3, 4, 6}

Output:
7
Explanation:
There are 7 full binary tree with
the given product property.
Four trees with single nodes
2  3  4  6
Three trees with three nodes
    4   ,
   / \
  2   2
   6    ,
  / \
 2   3

   6
  / \
 3   2

 

Example 2:
Input: N = 3
A[] = {2, 4, 5} 

Output: 7
Explanation: There are 4 full binary tree
with the given product property. 
Three trees with single nodes 2 4 5
One tree with three nodes
   6
  / \
  3   2

 

Your Task:  
You don't need to read input or print anything. Your task is to complete the function numoffbt() which takes the array A[]and its size N as inputs and returns the number of Full binary tree.

Expected Time Complexity: O(N. Log(N))
Expected Auxiliary Space: O(N)

Constraints:
1 ≤ N ≤ 104
1 ≤ A[i] ≤ 104

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Count the Number of Full Binary Trees

Output Window