Palantir Technologies
www.palantir.com Palo Alto, CA 500 to 999 Employees
Work in HR? Complete Your Profile

Interview Question for Embedded Analyst at Palantir Technologies: Mar 30, 2012

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

Yes | No
Inappropriate?

0 of 7 people found this helpful

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);
}
Yes | No
Inappropriate?

0 of 2 people found this helpful

Apr 17, 2012
Oops, forgot to include parseInt()
Yes | No
Inappropriate?

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))
Yes | No
Inappropriate?

6 of 6 people found this helpful

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
Yes | No
Inappropriate?

Oct 9, 2012
but if u do a binary search while multiplying then it will be faster then the subtraction method.
Yes | No
Inappropriate?