Please tell what is the problem in the code?

Not able to pass some test cases

Hey @sahilkhan2312000131
Debug for this

8
86922395

Output

4

hey @Kartikkhariwal1
As per the condition given in the question:
CB number once detected should not be sub-string or super-string of any other CB number.
Ex- In 4991 , both 499 and 991 are CB numbers but you can choose either 499 or 991 , not both.
So, if a CB number if found then the next CB number should start from the next element to the end of the previous CB number. Am I right??
Input: 8
86922395
My code’s output:
8 No
86 No
869 No
8692 No
86922 No
869223 No
8692239 No
86922395 No
6 No
69 No
692 No
6922 No
69223 No
692239 Yes
5 Yes
2

Hey @sahilkhan2312000131
Sorry for late reply was busy with something important.
Yes CB numbers should be non-intersecting.
In the above :
2
2
3
5
4
are the 5 non intersecting CB numbers.

So first check for all the substrinfsgs of length 1 and then length 2 and so on

Approach :slight_smile: *

  • 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.

Thank you so much @Kartikkhariwal1

1 Like

If your doubt is resolves then please mark it as resolved :slight_smile: