We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

Im not sure of this solution. This will not be working with this input:

51213332

The output should be 2 but will be 3 because it will count last digit of the series 3. This solution does not consider what if solution will be shorter than a month digit.

Sure, this will pass all validators but still... :).

## Birthday Chocolate

You are viewing a single comment's thread. Return to all comments →

The shortest method for the above python code

return sum(1 for x in range(len(s)) if sum(s[x:x+m]) == d)

Well done!

Im not sure of this solution. This will not be working with this input:

The output should be

`2`

but will be`3`

because it will count last digit of the series`3`

. This solution does not consider what if solution will be shorter than a month digit.Sure, this will pass all validators but still... :).

return sum(1 for x in range(len(s)) if sum(s[x:x+m]) == d and len(s[x:x+m]) == m )

That't beutiful thank you for sharing : i did this way but we can make way shorter by yours..

List comprehension is amazing

I agree but also his method is n * m time complexity sadly.