Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
[ad_1]
Discover the variety of leaf nodes in an ideal N-ary tree of top Okay.
Notice: As the reply might be very giant, return the reply modulo 109+7.
Examples:
Enter: N = 2, Okay = 2
Output: 4
Clarification: An ideal Binary tree of top 2 has 4 leaf nodes.Enter: N = 2, Okay = 1
Output: 2
Clarification: An ideal Binary tree of top 1 has 2 leaf nodes.
Method: This drawback might be solved based mostly on the commentary that the variety of leaf nodes in an ideal N-ary tree with top Okay shall be equal to NOkay. Use Modular exponentiation to calculate the ability modulo 109+7.
Observe the steps talked about under to implement the above concept.
Beneath is the implementation of the above method:
|
Time Complexity: O(logK)
Auxiliary House: O(1)
[ad_2]