CB Number Question

This is the brute force I have applied for this question. But don’t know what is wrong here, Please tell. Here is the link :- https://ide.codingblocks.com/s/407233.

Please also give a hint for the optimized approach of solving this question.

There is a subtle mistake in your approach, you need to check all the subarray in increasing size. That is you need to check first the subarray of size one then two and so on. Moreover, it is mentioned that the same character cannot be used twice you must check that as well.

Here is a link to the working code for your reference.

Done some changes please check once :- https://ide.codingblocks.com/s/407257

Also not able to understand the code you have used in solving the question. Is there any another way you can explain it please.

Hey, since we have to find maximum number of CB numbers and we can only use a character once it would be a better choice to first choose CB number smaller in size followed by CB number larger in size.
Correct approach:

Put loop on string that will give substring of every length.
create a function that will return true if the passed number is a CB number otherwise return false.
To put a check if the digit is already a part of the any other CB number, create an boolean array say, valid which store which digits till now has been a part of any other CB number.
Take a counter and increment if a CB number is found.
At the end print the count.

Hey, I have tried to code in the way you described in the algorithm, Please have a look at once what is wrong am i doing in this. Here is the link to the code of the question :- https://ide.codingblocks.com/s/407737

See if the given number is 123, you need to first check 1 then 2 then 3 then 12 then 23 then 123 but you are checking In order 1, 12, 123, 2, 23, 3. Which is wrong

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.