A question I got on my last interview:
Design a function f, such that: f(f(n)) == -n Where n<
Design a function f, such that:
f
f(f(n)) == -n
Where n<
n<
Works except int.MaxValue and int.MinValue
public static int f(int x) { if (x == 0) return 0; if ((x % 2) != 0) return x * -1 + (-1 *x) / (Math.Abs(x)); else return x - x / (Math.Abs(x)); }