2 test cases not passing
please help
Finding CB Numbers
Hello @Ankit-Sinha-1919950534781619,
There are two modifications required in your code:
-
The number can also contain more than 9 digits.
Thus, stoi() function would not work a string greater than 9 characters(digits).
num=stoi(str1);
Solution:
Rather use a loop to convert the string into a number. -
Your code is first looking for the largest CB number and then for smaller length numbers.
This way you would skip some CB numbers of smaller length.
Example:
12345643 (a CB number)
It can be broken down into more than 1 CB number.
Solution: Start checking for the numbers of smallest size i.e. 1 and then gradually increase the size. -
Make an array visited[n], to mark the indexes as visited (i.e. set it to 1).
This will help in keeping track of all the indexes of input array that have already been used in the previously detected CB number.
You can refer to the following code for better understanding:
Hope, this would help.
If you still have any doubts, feel free to ask.
Give a like, if you are satisfied.
This was so nice of u… @S18ML0016… u really debugged my code and found all the faults in the code and gave all the suitable alternatives…Thankx again for ur benifitting reply
Anytime.
Please, mark this doubt as resolved if you have no more questions regarding this thread.
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.