Pergunta de entrevista da empresa LinkedIn

In the first interview: they asked me to implement a pow(base, exp) function. I did a linear solution and they asked me to improve it (time complexity). There's a logN solution for this problem.

Respostas da entrevista

Sigiloso

10 de jan. de 2014

Complexity of log(n) implemented via ruby:- def pow(a,b) if n == 0 return 1 else half_pow = pow(a, b/2) if b%2 == 0 return half_pow * half_pow else return half_pow * half_pow * a end end

2

Sigiloso

29 de jan. de 2014

The first check should be: if b == 0; The remaining code is perfect. Thanks!