CB number once detected should not be sub-string or super-string of any other CB number.
Can you explain this
hello @sagar_aggarwal
consider this number.
12345 (let say 23 and 34 are cb number just an example)
then by this statement they mean if u have considered 23 ( i,e 12345) in ur answer then u can not consider 34 (i,e 12345) (because 3 will overlap i,e 12345)
isvalid function is checking whether we are allowed to consider sā¦e-1 as cb number of not.
when we r allowed ?
we r allowed to include this only when we havent consider any part of this segment in any of our previous considered cb numbers.
so we are running a loop from i=start to end-1.
if visitied[i] =true that means we have already considered ith digit in some other answer so we cannot include it now.
got it thanks aman for beautiful explaination
is any body there???
ur approach is bit wrong.
but whats wrong with my logic why we need to check for substrings of length ?
also how do i find substring of lengths?
according to me my logic does same as yours
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)
and that is the reason why we are first considering all small length string and then bigger length string.
read about subtr stl function .(to find subtring of given length and from a given index)
you are brilliant thanks