Given an array with integer 0 to N, how many ways to arrange it such that at position i of the array, we cannot have i inserted in it?
For example, N = 2
The following arrangements is valid:
- 1,2,0
- 2,0,1
Thus, the answer is 2 arrangements
I can't think of a non-brute force method to do this in O(1) time, can anyone help me out?