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
2 1 3
For the above test case, the answer should be yes but your program gives output no because of
See that, the value of A[i] can be at a position equal to the number but it shouldn’t be in order.