Array ( [0] => [1] => questions [2] => HackwithInfy-Previous-Questions [3] => Fast-Exponential )
Login to see Discussion
i)create a method power which takes base and exponent as arguments
ii)if exponent is 0 return 1 if exponent is 1 return base
iii) calculate power (base,exponent/2) and store in r
iv)if exponent is even return r*r else return r*baser
v)in main method take base and exponent as input from the user
Time Complexity: O(log m)
Space Complexity: O(1)
Note :
Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.
Login to see Solution