Programming Job Interview Challenge #4 Answer
Posted: 5/19/2008 5:48:47 PM
So one of the guys over at dev102.com
has been posting job interview questions. While the most recent isn't the best interview question in the world, I thought I'd share the answer if anyone is interested.
Here is the question
How would you implement the following method: Foo(7) = 17 and
Foo(17) = 7. Any other input to that method is not defined so you can
return anything you want. Just follow those rules:
- Conditional statements (if, switch, …) are not allowed.
- Usage of containers (hash tables, arrays, …) are not allowed.
The answer is crazy simple. Highlight the text below to reveal the answer.public int Foo(int x)
return -1 * x + 24;
My Algebra teacher would be so proud.