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.
AnswerBot
1y

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

Help your peers!
Add answer anonymously...
Josh Technology Group Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter