I coded the solution myself after reading the solution but it dosent seem to be working

hello @vipulch

ss

correct this part of ur code.

the outer loop is for length so it should start from 1 and run till length <=str.size()
the second loop should start from j =0 /

the thist loop must start from j and go till j+i-1
refer this->

but why? my code is also creating all the possible substrings like that one, can you please explain why it still dosent work?

consider this number (assuming 1234 is a cb number and 2,3,4 are also cb number)
1234

now what ur 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)

and that is the reason why we are first considering all small length string and then bigger length string.

but sir if if consider 4321, the first iteration will choose 321 as a cb(assuming it is one) , and then the next iterations will not choose any numbers since the 321 is already chosen, so if 2 is also a cb it wont get chosen

…

that the flaw i want to convey.
since we want to maximize cb number. first we need to find all 1 lenght cb number then all 2 lenght then all 3 length so on

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.