CB number once detected should not be sub-string or super-string of any other CB number

Hello,
I tried to approach this problem and here is my solution.

Its a bit complex but its working, now the only issue I’m facing is my code is not able to fulfill this criteria:
CB number once detected should not be sub-string or super-string of any other CB number.
Can you suggest or make necessary edits in my code so that this condition can also be fulfilled.

Thanks in Advance

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