my sol is https://ide.codingblocks.com/s/136740
what is the error in it
Finding cb numbers
Hello @royprincejmp,
-
There is a problem in the conversion of string to int i.e. k
Try to print the following:
k=s[i];
cout<<k<<endl; //ADD these
You will understand your mistake. -
If you would print num, then you would realise that your code is initially checking for all the subarrays/substrings that are starting from index i=0. And after detecting a CB number, it makes i=j. 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 substrings 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.