I found a bug in custom testcase

The problem already points it out that the length of the array will be n while the integer in the array will range from [0, n] inclusive, so in your case the length of the array is 2 then the n will be 2 which is also the biggest but your test case contains 3 which is kind of 'overflow', bigger than the valid biggest 2. So the result can be unexpected.