Pergunta de entrevista da empresa Uber

Multiply 2 long numbers without using multiplication.

Respostas da entrevista

Sigiloso

20 de mar. de 2017

- (NSInteger)multiplyNum:(NSInteger)num1 with:(NSInteger)num2 { if (num2 == 0 ) return 0; if (num2 > 0) return (num1 + [self multiplyNum:num1 with:num2-1]); if (num2 < 0) return -[self multiplyNum:num1 with:-num2]; return 0; }

Sigiloso

29 de set. de 2016

Bit wise operation is a possibility along with addition. I wonder if this question is more about thinking outside of the box than coming up with the most efficient alternative.

Sigiloso

9 de jul. de 2017

def multiply(num1,num2): results=0 results_array=[] for i in range (1,num2+1): results += num1 print(results) a=5 b=5 multiply(a,b)