3 test Case Failed getting Wrong Ans

code:

your logic for solving this question is wrong, you are essentially starting from given index and findiing a CB number and then starting from that index, but instead you should look for smaller CB numbers first, for example in case of
4
4567

your code would give 1, i.e 4567 itself, but the correct solution would be 2 i.e 5, 7.
In correct approach we would look for smallest CB number first.

Correct approach:

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

Code:

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.