Balanced Binary Trees Problem Statement
You are provided with an integer 'H'. Your task is to determine and print the maximum number of balanced binary trees possible with height 'H'.
A balanced binary tree is defined such that for every node, the difference between the heights of the left and right subtrees is no more than 1.
Your answer should be printed modulo 1e9+7.
Example:
Input:
H = 2
Output:
3
Explanation:
There will be a total of 3 different balanced binary trees with height 2: one with a single root and other nodes branching to one side, one with the root having a left subtree which is taller by one node, and one with the root having a right subtree which is taller by one node.
Constraints:
- 1 <= T <= 50
- 1 <= H <= 106
- Time Limit: 1 sec.
Input:
The first line contains a single integer 'T' representing the number of test cases to be executed. For each test case, there is a single integer 'H' indicating the height of the tree.
Output:
For each test case, produce an integer representing the number of balanced binary trees that can be constructed with the given height. Each test case's result should be printed on a new line.
Note:
You do not need to print anything as it will be handled for you. Simply implement the function and return the result.
The maximum number of balanced binary trees possible with a given height is to be counted and printed.
A balanced binary tree is one in which the difference between the left and right subtree heights i...read more
Top Josh Technology Group Software Developer interview questions & answers
Popular interview questions of Software Developer
Reviews
Interviews
Salaries
Users/Month