I can't figure out the error

Hello @coe17b030,

If you would print sum, then you would realize that your code is initially checking for all the sub-arrays/sub-strings that are starting from index i=0. And after detecting a CB number, it makes i=j+1. Correct?
Like in the example mentioned in my previous reply, it detected two CB numbers though actually there were 4 CB numbers:
Example:
11
44166181111
Your Output:
2
Detected CB numbers:
44166181
11
Actual:
41
61
11
11

Solution:

Check for all the sub-strings starting from smallest size i.e. 1, then gradually increase the size.
Also, use an array to mark the indexes that are used in the CB numbers that are already detected.
Correct your code and let me know if you don’t understand something.

Approach:

  1. check for all sub-strings of the given string of digits, starting from the all strings of length 1 and then gradually checking for the strings of increasing size:

    1.1. check if the sub-string is CB number: for this, create a function
    1.1.1. if sub-string is 1 or 0 return false.
    1.1.2. if sub-string is any of the {2,3,5,7,11,13,17,19,23,29}, then return true.
    1.1.3. if sub-string is divisible by any of the {2,3,5,7,11,13,17,19,23,29}, then return false.
    1.1.4. return false

    1.2. now if it is a substring:
    1.2.1. call a function that marks the index as visited for indexes which are part of that CB number.

    1.3. increment the count for CB number.

  2. Print the count

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

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.