Check the way you read the data…
See here an example where your code fails:
Check the way you read the data…
See here an example where your code fails:
Sorry. Your code is wrong.
It fails with:
1
6
1 10 2 11 3 14
I don’t check why you get TLE, but your algo is wrong. You check the values against {1,2,3…,n}, but it is not said that the Ai are a permutation of {1,…n}.
@shashi jey
Your solution works only if the numbers are from 1 to N.
But the input can contain any numbers.
Ex: N = 4 and A[]={1 3 8 6}.
Check my solution dude , I didn’t even used fast i/o!