two testcases are showing the wrong answer . please guide me.
Wrong answer for two test cases
hello @somilgupta4
a) why r u checking for prime. (follow the definition of cb number for checking)
b) consider this number (assuming 1234 is a cb number and 2,3,4 are also cb number)
1234
now what u logic will do . it will first consider (1,then 12 then 123 and then 1234) right?
and because 1234 is cb number and it is valid as well.
u will include it and mark all positions ie position for 1 2 3 and 4 as 1.
and because all ur digit are marked u will not consider any other cb number.
so ur code will print 1.(ie 1234 as only cb number)
but correct answer is 3 i,e (2,3,4)
correct approach->

a) 4 isnt a CB number as divisible by 2 ( correct me if i am wrong ) , but i wld change the condition if u want. ( numbers not divisible by this set are prime only)
b) check the code carefully, if the number has satisfied the condition(of being prime) I increment to the place where j ends.
waiting for reply
i
note -> i m not saying that 4 is cb number. i m telling u to assume that 4 is cb number.
just to explain u why ur code is failing
sir can u please take an example which satisfies the condition ( given for CB number) and rejects my code . i ll understand myself
beacuse it wont consider 1, 12 ,123 ,1234 . since if we get a CB number i increment i to that of j .
yeah right , u will increment to j.

here do a dry run for case. when i=0
and when this is given
lets take 2357( as 2,3,5,7 are CB numbers ) then my code would take 2 as CB number increment the count and pass the index (j) to i
step :-2
i increaments it and now is on first index which is 3 so every individual number would be accessed and count would be incremented.
and i have decleared the string temp outside the j loop so it should refresh the memory everytime i declare it ( according to me )
but if consider 1234, and i=0
then the first cb number u will find is 1234 .
and then u will update ur i with j i,e 3.
which is the last index of the loop . and ur loop will end .
and u will print only 1. (i,e 1234 )
but correct output is 3 ( 2,3,4)
ok sir got it thank you so much sir !
one more doubt sir , my code was compiling successfully up till afternoon now its showing some error .
many of the test cases passed too .
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.