Subarray Division 1

  • + 0 comments

    Fastest Python solution!!! Solution uses sliding window or queue (which ever makes it easier for you to think about this problem.) Solution also uses some savvy indexing math.

    def birthday(s, d, m):
        # Write your code here
        count = 0
        total = sum(s[:m])
        if total == d:
            count += 1
        for i in range(m-1, len(s)-1):
            total += s[i+1] - s[i+1-m]
            if total == d:
                count += 1
        return count