Why my test cases are not passing?

3 test cases are not passing

Hello @Deepanshu_garg ,

The logic you have applied for visited is wrong.
Run your code for the following input:

9
232381615

I would suggest you to make following changes in your code before executing it so that you can see the CB numbers it is guessing.
if(isValid(visited,i,j) && isCBNO(number))
{
count++;
cout<<number<<" ";
for(int k=i;k<=j;k++)
{
visited[k] = 1;
}
}

Try to correct your code on your own.
If you still face problem, feel free to ask.
Hope, this would help.

Hi,I have removed concept of visited still its not passing all testcases

I apologize for replying late.

BTW, i didn’t ask you to remove visited logic.
Actually, the problem in your code is of the order you are checking for subarrays.

Suggestion: Start from shortest to largest subarray as you have to find the maximum count.

I have modified you code.
Click here to see modification.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.