Question d’entretien chez Palantir Technologies

write a function that finds the remainder between two numbers using only addition, sutraction and multiplication.

Réponses aux questions d'entretien

Utilisateur anonyme

5 juil. 2012

This is pretty easy, guys. You don't want to be doing extraneous multiplication because it is veryyyy slowwwww. X and Y are the numbers to find the remainder of, assume X > Y. while(x > y) { x = x - y } return x Example: 10, 4 10 > 4 x = 10 - 4 = 6 6 > 4 x = 6 - 4 = 2 2 < 4 return 2

11

Utilisateur anonyme

10 oct. 2012

but if u do a binary search while multiplying then it will be faster then the subtraction method.

Utilisateur anonyme

2 juil. 2012

the first solution is wrong..(1/y) is division dude.. I think the solution is something like this. Suppose x, y are your numbers and you want to find remainder(y/x). z = x while z < y i++ z = x*i end remainder = y - (z*(i-1))

Utilisateur anonyme

17 avr. 2012

Oops, forgot to include parseInt()

Utilisateur anonyme

17 avr. 2012

var x; var y; var solution; var TestSol; var Remainder; x * (1/y) = solution; solution*y = TestSol; if (TestSol = x) { document.write("Remainder is zero"); } else { x - TestAns = Remainder; document.write (Remainder); }

1