Question d’entretien chez Meta

Implement a function to compute cubic root what is the time complexity?

Réponses aux questions d'entretien

Utilisateur anonyme

3 mars 2012

There are two traps in this question if you use binary search: 1. the value can be negative 2. the cubic root of any values between -1 and 1 is larger than the value I avoided the first but failed on the second

2

Utilisateur anonyme

28 mars 2012

Binary search works, compute the value and multiply it by -1 if the input was negative.

1

Utilisateur anonyme

9 avr. 2012

Newton's method is the best.

1

Utilisateur anonyme

20 févr. 2012

1. binary search 2. Newton's method

1

Utilisateur anonyme

3 mars 2012

There is only one technical question Half of the time was spent on my past experience

1

Utilisateur anonyme

3 mars 2012

got rejection just because this reason? How was your performance in other 2 questions?

Utilisateur anonyme

28 juil. 2012

Time Complexity of optimized solution: O(logn) Let us extend the pow function to work for negative y and float x. /* Extended version of power function that can work for float x and negative y*/ #include float power(float x, int y) { float temp; if( y == 0) return 1; temp = power(x, y/2); if (y%2 == 0) return temp*temp; else { if(y > 0) return x*temp*temp; else return (temp*temp)/x; } } /* Program to test function power */ int main() { float x = 2; int y = -3; printf("%f", power(x, y)); getchar(); return 0; }