Can you help me out with this problem?

I can’t understand how to approach it?

Hey @isingh , here I am sharing one of the possible approaches :

According to the Problem the work is to find the Max CB numbers from the given number.

  • As to work on substrings of the given number, we will capture the element into the String instead of integer .
  • The number ‘n’ given is nothing to do with our approach(as we are working on String) but can be useful in other approaches.
    Intuition to solve this problem:
  • 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.

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.

https://ide.codingblocks.com/s/336031 . I am trying hard to debug the code but I don’t know where I am going wrong, please help me out.

hello @isingh the problem in your code is that you are checking or running the loops till the end of the string .
you have to find the relation how can we do that .
here is the correct code according to your logic .

if you have problem in understanding any line please write here .
i will explain you .
Happy Learning !!