Issue in the Finding CB Numbers problems

https://ide.codingblocks.com/s/57692
I am not able to find out what mistake I have made in this code.
4 test cases are not being satisfied and in two, time limit exceeded.
Plz help.

Hi Abhishek, you have written the entire code inside a single function, your logic is unclear and incomplete.
Here is what you can do to solve this problem:

  • Capture the given element into a string instead of integer. 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.

Try to modularise your program and reply to this thread if you still face any issue.

1 Like