Skip to content
Onsite

Subarray Division

EasyP3Coding

A chocolate bar is a row of squares, each with an integer written on it. s[i] is the number on square i.

Count the ways to choose a contiguous segment of exactly m squares whose numbers add up to d. Segments are different if they start at different positions.

Example 1

Input
s = [1,2,1,3,2], d = 3, m = 2
Output
2

Example 2

Input
s = [1,1,1,1,1,1], d = 3, m = 2
Output
0

Example 3

Input
s = [4], d = 4, m = 1
Output
1

Constraints

  • 1 <= s.length <= 100
  • 1 <= s[i] <= 5
  • 1 <= d <= 31
  • 1 <= m <= 12

Hints

Run checks the 3 visible tests, Submit all 11.