Pregunta de entrevista de Meta

Multiply two big ints.

Respuestas de entrevistas

Anónimo

30 abr 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

Anónimo

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

Anónimo

30 abr 2015

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

1