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
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 11. ⌘Enter runs, ⌘⇧Enter submits.