in case of input 81615 8161 and 5; 61 and 5 are pairs
so we have to choose shortest prime number or any case
What is the output
you have to choose smallest prime numbers that are not overlapping
can you tell me how to approach it?
Suggested approach:
- check for all sub-strings of the given string of digits, starting from the 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
and how should i divide in these possible sub strings
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 in other approaches.
Intuition to solve this problem: - 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.
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.