Loading...
Is this your company?
Write a power function power(a , b) returns a^b
Anonymous
def power(a, b): return a**b
double pow(int a,int b) { if(b0) { if(b%2==1) res*=a; a*=a; b>>1; } return res }
long power(int a, int n) { if(n%2==0) return power(a,n/2)*power(a,n/2); else if (n%2==1&&n!=1) return power(a,n-1)*a; else //n==1 return a; }
def power(a,b): if b is 1: return a return a * (power(a, b--))
There are some conditions you are missing. What if b is <=0 ?
The conditions made by the Hulu rep was to assume b > 0. However there is a better way to do this problem.
int power (double a, int b) { for (int i = 1, i <= b, i++) { a *= a; } return a; }
Stay ahead in opportunities and insider tips by following your dream companies.
Get personalized job recommendations and updates by starting your searches.
Get actionable career advice tailored to you by joining more bowls.
Check out your Company Bowl for anonymous work chats.