Test cases not getting passed completely


Here is my solution to the above problem.
Can i ples tell me the mistake i am making due to which all the test cases are not getting passed?

@TusHar-AroRa-2294450460870717
Try to debug for this Input:
8
86922395
correct output : 4

@aa1 Can u ples tell what does this statement implies " In 4991 , both 499 and 991 are CB numbers but you can choose either 499 or 991 , not both."
499 and 991 are not substrings or superstring of each other then why cant we chose both?

@TusHar-AroRa-2294450460870717
They are not considering 4991 as a CB number.
Instead, 499 and 991 are CB number that can be formed from the above number 4991.
But, we can select only one as the multiple uses of the same character is not allowed and 99 is common to both.It means that no two CB numbers should share a character for example in 4991, if you detect 499 as CB number then you cant use first, second and third character in the 4991 for other CB numbers.

for example In, 994991, if you make 499, the string will not become 991, it’ll still remain 994991, just you wont be able to use 4, 9, 9.

https://ide.codingblocks.com/s/322403 i tried to resolve it via dp approach.Althought the last test case which u gave is giving correct answer but still in this approach as well,2 test cases are not getting passed.

@TusHar-AroRa-2294450460870717
go through this code