can anyone tell me where i am going wrong? i am unable to figure out

this is the question

this is my solution

Hey @rishird94,

To solve the problem, there are three basic condition

  1. Shouldn’t be in order (increasing)
  2. if there n chapters than chapters cannot be greater than n
  3. If a chapter is repeated then also output will be no.

I think your solution goes wrong for 3rd condition.

Check out this solution in C.

Hope this helps!

4 Likes

If you have any other query comment below, I’ll try to help!

1 Like

actualy,i have taken care of the third condition acc to me. because in my solution, as soon as the first occurence of a particular num happens in the input array, the same num from the ‘ar’ array list is removed,so wen there is 2nd occurence of that same number in the input array,it wont find it in the “ar” araylist and hence will exit with a no.
can u please suggest a test case for wich it wont be successful?

Here this test case
1

3

2 1 3

For the above test case, the answer should be yes but your program gives output no because of

if(a[i]== i+1)

           continue;

           ar.add((i+1));

See that, the value of A[i] can be at a position equal to the number but it shouldn’t be in order.