I’m super close. But I cannot figure out right formula. It doesn’t count amount of the similar substrings correctly. I mean the output is wrong.
2 Answers
Look at your asub and bsub right before returning an answer. (you can use print to see what they are). Looks like they're getting re-defined for each i rather than accumulating a list of all possible options.
You have some substrings that are shorter than the others because there are no n
characters left at index i
.
How many substrings of length n
can you have in a string of length len(a)
? n
is part of the formula that goes into the range
call.
-
when I do for i in range ( len(a)- n-1) I get the same result as without n. Commented Oct 1, 2018 at 15:34
-
-n
looks fine, but imaginelen(a)
andn
were the same, how many possible substrings would you expect?-1
?– BlauelfCommented Oct 1, 2018 at 16:17 -
I rearranged the code and it worked. I put everything in return and some magic happened. Commented Oct 2, 2018 at 4:13