Question d’entretien chez Hulu

Write a power function power(a , b) returns a^b

Réponses aux questions d'entretien

Utilisateur anonyme

18 oct. 2018

def power(a, b): return a**b

2

Utilisateur anonyme

27 juil. 2014

double pow(int a,int b) { if(b0) { if(b%2==1) res*=a; a*=a; b>>1; } return res }

1

Utilisateur anonyme

27 févr. 2013

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; }

1

Utilisateur anonyme

17 sept. 2013

def power(a,b): if b is 1: return a return a * (power(a, b--))

1

Utilisateur anonyme

4 déc. 2012

There are some conditions you are missing. What if b is <=0 ?

Utilisateur anonyme

4 déc. 2012

The conditions made by the Hulu rep was to assume b > 0. However there is a better way to do this problem.

Utilisateur anonyme

7 mai 2012

int power (double a, int b) { for (int i = 1, i <= b, i++) { a *= a; } return a; }

2