Finding CB Number

I am able to calculate all possible cb numbers but I am not able to figure out how I can remove those numbers from an arrary of possible cb numbers where two or more numbers in an array share a common substring. Can anyone help me with a efficient approach to remove such numbers? Thanks.

Hello @18bcs036,

  1. For this, you can use extra memory and define an array called visited to mark the indexes as visited if they are a part of the detected CB number and then make sure the index of the new CB number should not be marked.

  2. As you have to maximize the number of CB numbers. So, first check for all substrings of length 1 and increment their size gradually.

You can refer to the following code:

Hope, this would help.
Give a like if you are satisfied.

1 Like

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.