Hey @rishird94,
To solve the problem, there are three basic condition
- Shouldnât be in order (increasing)
- if there n chapters than chapters cannot be greater than n
- 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!
If you have any other query comment below, Iâll try to help!
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.