Finding CB Number

In the given example

81615

OUTPUT - 2

According to given explanation there are only two numbers 61 & 5 which are CB numbers BUT

8161 is also a CB Number. so according to me OUTPUT = 3. so where I am wrong Please correct me.

hey @rahul_bansal
you gave a nice try and i am happy that you analysed the test case carefully.
you have missed a small point from the question that

  • 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 u take 61 as CB number then 8161 cannot be a CB number as it contains 61 as substring which is already a CB number

hope i have cleared your doubt
happy coding :wink:

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.

Actually I am doing this question by this way : https://ide.codingblocks.com/s/646795

But now I have only one approach in my mind that is I will put all the numbers of point2 in If statement and then solved this.

Is there any other approach for this problem or can u suggest any correction in above code?

@rahul_bansal you can refer this vedio for more clarity of the above question.

you can check for every substring if it is CB number or not and if it is a CB number you can store it in a map.
then for other substring ‘B’ you can check from map if any substring of ‘B’ is present in map then do not add ‘B’ to the map