Algo++ : Finding CB numbers

I have solved this question in o(n^2) where n=no. of digits of string . Is there a way to solve it in a better complexity

@amandahiya.3572 hey aman dahiya can I see your approach. so that I can suggest you or may we also implemented the same.

code link : https://ide.codingblocks.com/s/105376

@amandahiya.3572 hey aman
I was used this approach
According to the Problem the work is to find the Max CB numbers from the given number.

As to work on substrings of the given number, we will capture the element into the String instead of integer .
The number ā€˜n’ given is nothing to do with our approach(as we are working on String) but can be useful acoording to your approach.
Intuition :
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.