Designing function f(f(n)) == -n
Asked 07 September, 2021
Viewed 1.2K times
  • 62
Votes

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?

30 Answer