Skip to the code
+25 XP

#49 Multiple of K Streak Exists

medium

A loyalty program awards a badge when a customer has a run of at least two back-to-back orders whose item counts add up to a multiple of k. The item counts are in nums.

Write hasMultipleStreak(nums, k) that returns true if such a run exists. Note that 0 is a multiple of every k.

Example 1

Input: nums = [5,3,8,1], k = 4
Output: true

5 + 3 = 8, a multiple of 4.

Example 2

Input: nums = [1,2,4], k = 8
Output: false

The runs of two or more add up to 3, 6, and 7.

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^9
  • 1 <= k <= 2^31 - 1
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).