Example not clear

sir as in example 4991 is mentioned as a cb number but it is divisible by 7
also sir according to the problem a cb number cant be the substring of another cb number ,i applied all the logic still getting WA in many cases
please check my code…


sir please check it

Hello @anupanu23,

Please, read the question properly.
They are not considering 4991 as a CB number.
Instead, 499 and 991 are CB number that can be formed from the above number 4991.
But, we can select only one as the multiple uses of the same character is not allowed and 99 is common to both.

You can follow the following approach if facing any issue:

Approach:

  1. check for all sub-strings of the given string of digits, starting from 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.
If you still have any issue, feel free to ask.
Give a like if you are satisfied.

sir i had downloaded all test cases and ran each of them on cb compiler and the answer is exactly same …as expected but while submittion 3 test cases are failing …

https://ide.codingblocks.com/s/144635 here is my code

Hello @anupanu23,

It is actually skipping the CB numbers:
Example:
11
44166181111
Your Output:
2
it detected: {44166181, 11} as CB numbers
Expected Output:
4
{41, 61, 11, 11}

Solution:
Check for all the substrings starting from smallest size i.e. 1, then gradually increase the size.

Hope, this would help.

1 Like

thanks ! i got my mistake

Anytime @anupanu23,

Please, mark this doubt as resolved.
BTW, i won’t mind a like.

1 Like

how to like there is no option

@anupanu23,

There is a heart after my reply.
You can click on it if you like any response.

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.

1 Like