Max Heap is a special kind of complete binary tree in which for every node the value present in that node is greater than the value present in it’s children nodes. If you want to know more about Heaps, please visit this link
So now the problem statement for this question is:
How many distinct Max Heap can be made from n distinct integers
In short, you have to ensure the following properties for the max heap :
Let us take an example of 4 distinct integers. Without loss of generality let us take
1 2 3 4 as our 4 distinct integers
Following are the possible max heaps from these 4 numbers :
4 / \ 3 2 / 1
4 / \ 2 3 / 1
4 / \ 3 1 / 2
These are the only possible 3 distinct max heaps possible for 4 distinct elements.
Implement the below function to return the number of distinct Max Heaps that is possible from
n distinct elements.
As the final answer can be very large output your answer modulo
Input Constraints : n <= 100
NOTE: Note that even though constraints are mentioned for this problem, for most problems on InterviewBit, constraints are intentionally left out. In real interviews, the interviewer might not disclose constraints and ask you to do the best you can do.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.