this problem is quite difficult to understand …
please can you elaborate the solution of 81615
like which subsequences is CB number and how…?
CB number problem
Hello @nikhilmeena
In the question you have to find the maximum number of CB numbers that you can form from the input:
In the Sample Testcase:
5
81615
There are at max two CB numbers that we can form:
- 61
- 5
Thus, the output is 2.
Approach:
-
check for all sub-strings of the given string of digits, starting from all strings of length 1 and then gradually checking for the strings of increasing size:
1.1. check if the sub-string is CB number: for this, create a function
1.1.1. if sub-string is 1 or 0 return false.
1.1.2. if sub-string is any of the {2,3,5,7,11,13,17,19,23,29}, then return true.
1.1.3. if sub-string is divisible by any of the {2,3,5,7,11,13,17,19,23,29}, then return false.
1.1.4. return false
1.2. now if it is a substring:
1.2.1. call a function that marks the index as visited for indexes which are part of that CB number.
1.3. increment the count for CB number. -
Print the count
Hope, this would help.
If you still have any issue, feel free to ask.
Give a like if you are satisfied.
sir i’ve completed my whole code but i m stuck in a part where we suppose to check whwter the current string is sub part or super string …?
Hello @nikhilmeena,
And why do you have to do that?
As you have to call a function that marks the index as visited for indexes which are part of that CB number.
Explanation:
Create a boolean array(say visited) that marks the index of the input string as true if the element at that index has already been a part of a CB number that was detected earlier.
Also, start checking for the smallest CB numbers (say of size 1) then increase the size gradually.
Reason:
You have to maximize the CB numbers detected.
Please, share your code.
That will help me to understand your logic/mistake better.
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.