employer cover photo
employer logo
employer logo

Palantir Technologies

Is this your company?

Palantir Technologies Interview Question

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

Interview Answers

Anonymous

Jul 5, 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

Anonymous

Oct 10, 2012

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

Anonymous

Jul 2, 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))

Anonymous

Apr 17, 2012

Oops, forgot to include parseInt()

Anonymous

Apr 17, 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