Skip to the code
+25 XP

#47 Streaks Divisible by K

medium

A rewards program pays out whenever a streak of back-to-back daily point changes in points adds up to a multiple of k (including 0).

Write divisibleStreaks(points, k) that returns how many streaks qualify. Different start or end days count as different streaks.

Example 1

Input: points = [3,1,2,6,-3], k = 3
Output: 10

For example [3], [1, 2], [6], and [3, 1, 2, 6, -3] all add up to multiples of 3; ten streaks do in total.

Example 2

Input: points = [5], k = 9
Output: 0

5 isn't a multiple of 9.

Constraints

  • 0 <= points.length <= 10^5
  • -10^4 <= points[i] <= 10^4
  • 1 <= k <= 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).