Is it possible to solve this problem in O(n) given that the numbers can only be in the range from 1 to 1000?
P.S: I tried solving this in O(n) but I am getting WA. I also created a random input generator and compared my output with the correct code for n = 100 and values from 1 to 100 but didn't find any difference.
My Code