Pergunta de entrevista da empresa Meta

Multiply two big ints.

Respostas da entrevista

Sigiloso

30 de abr. de 2015

The above code is neat; unfortunately, it does not account for *big* integers being multiplied. So, suppose we have two numbers that are close to the integer limit. What would happen when we try to multiple them? In addition, what happens when one of the integers is negative?

3

Sigiloso

24 de abr. de 2015

public static int bitwiseMultiply(int a, int b) { if (a == 0 || b == 0) { return 0; } if (a == 1) { return b; } else if (b == 1) { return a; } int result = 0; while (b >= 1) { if ((b & 1) == 1) { result = result + a; } a >= 1; } return result; }

Sigiloso

30 de abr. de 2015

Java Provides multiply() method for BigInteger datatype. It can be used directly.

1