You are viewing a single comment's thread. Return to all comments →
One liner is always better, but i dont really like to compress the size, moreover this is more readable:
def getWays(squares, d, m):
count = 0
for i in range(0,len(squares)+1-m):
if sum(squares[i:i+m]) == d:
why is the range subtracted from len()+1?
so that when the sliciing happens on list squares[i:i+m] , it does not go above the index limit.
as you can see i am doing i+m , while i is going from 0, to len()
In such case, you need to reduce the window.
This is known as Sliding window algorithm.