Regarding the error
Hey @gargshivam2001
Your approach is incorrect
Say for this
86922395
in the above :
2
2
3
5
4
are the 5 non intersecting CB numbers.
So first check for all the substrings of length 1 and then length 2 and so on
Approach
*
- 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.
Here
bool is_cb_number(string s)
{
long long num = stoint(s);
if (num == 0 || num == 1) {
return false;
}
int arr[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 };
for (int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++) {
if (num == arr[i]) {
return true;
}
}
for (int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++) {
if (num % arr[i] == 0) {
return false;
}
}
return true;
}
Use this for reference for is_cb function
4 is a cb no. how???
Oh sorry ignore 4
Written that by mistake
it has 4 cb numbers
2
2
3
5
sir does we have to check the value of the digit or the index for value???
as in your output 2 is getting counted twice
Because 2 is repeated twice
Value of digit
if value of digit is getting checked then why 2 is counted twice it should be counted only once
Oh u have to count the maximum CB numbers u can get in a string it doesn’t matter if they are getting repeated but if u pick any CB number then u have to make sure u dont pick any CB number which has that no in it
Say X2Y here X & Y are some string of digits so if u pick 2
then U have to solve it for X & Y u cant pick any other CB no with this 2 in it
I thought u are asking something else thats why I said value of digit
please check sir