Interview question: f(f(n)) == -n

Posted by Hrvoje Prgeša on Stack Overflow See other posts from Stack Overflow or by Hrvoje Prgeša
Published on 2009-04-08T21:04:18Z Indexed on 2010/03/18 23:11 UTC
Read the original article Hit count: 338

A question I got on my last interview:

Design a function f, such that:

f(f(n)) == -n

Where n is a 32 bit signed integer; you can't use complex numbers arithmetic.

If you can't design such a function for the whole range of numbers, design it for the largest range possible.

Any ideas?

© Stack Overflow or respective owner

Related posts about job-interview

Related posts about interview-questions