|
| 1 | +<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>, an integer <code>modulo</code>, and an integer <code>k</code>.</p> |
| 2 | + |
| 3 | +<p>Your task is to find the count of subarrays that are <strong>interesting</strong>.</p> |
| 4 | + |
| 5 | +<p>A <strong>subarray</strong> <code>nums[l..r]</code> is <strong>interesting</strong> if the following condition holds:</p> |
| 6 | + |
| 7 | +<ul> |
| 8 | + <li>Let <code>cnt</code> be the number of indices <code>i</code> in the range <code>[l, r]</code> such that <code>nums[i] % modulo == k</code>. Then, <code>cnt % modulo == k</code>.</li> |
| 9 | +</ul> |
| 10 | + |
| 11 | +<p>Return <em>an integer denoting the count of interesting subarrays. </em></p> |
| 12 | + |
| 13 | +<p><span><strong>Note:</strong> A subarray is <em>a contiguous non-empty sequence of elements within an array</em>.</span></p> |
| 14 | + |
| 15 | +<p> </p> |
| 16 | +<p><strong class="example">Example 1:</strong></p> |
| 17 | + |
| 18 | +<pre> |
| 19 | +<strong>Input:</strong> nums = [3,2,4], modulo = 2, k = 1 |
| 20 | +<strong>Output:</strong> 3 |
| 21 | +<strong>Explanation:</strong> In this example the interesting subarrays are: |
| 22 | +The subarray nums[0..0] which is [3]. |
| 23 | +- There is only one index, i = 0, in the range [0, 0] that satisfies nums[i] % modulo == k. |
| 24 | +- Hence, cnt = 1 and cnt % modulo == k. |
| 25 | +The subarray nums[0..1] which is [3,2]. |
| 26 | +- There is only one index, i = 0, in the range [0, 1] that satisfies nums[i] % modulo == k. |
| 27 | +- Hence, cnt = 1 and cnt % modulo == k. |
| 28 | +The subarray nums[0..2] which is [3,2,4]. |
| 29 | +- There is only one index, i = 0, in the range [0, 2] that satisfies nums[i] % modulo == k. |
| 30 | +- Hence, cnt = 1 and cnt % modulo == k. |
| 31 | +It can be shown that there are no other interesting subarrays. So, the answer is 3.</pre> |
| 32 | + |
| 33 | +<p><strong class="example">Example 2:</strong></p> |
| 34 | + |
| 35 | +<pre> |
| 36 | +<strong>Input:</strong> nums = [3,1,9,6], modulo = 3, k = 0 |
| 37 | +<strong>Output:</strong> 2 |
| 38 | +<strong>Explanation: </strong>In this example the interesting subarrays are: |
| 39 | +The subarray nums[0..3] which is [3,1,9,6]. |
| 40 | +- There are three indices, i = 0, 2, 3, in the range [0, 3] that satisfy nums[i] % modulo == k. |
| 41 | +- Hence, cnt = 3 and cnt % modulo == k. |
| 42 | +The subarray nums[1..1] which is [1]. |
| 43 | +- There is no index, i, in the range [1, 1] that satisfies nums[i] % modulo == k. |
| 44 | +- Hence, cnt = 0 and cnt % modulo == k. |
| 45 | +It can be shown that there are no other interesting subarrays. So, the answer is 2.</pre> |
| 46 | + |
| 47 | +<p> </p> |
| 48 | +<p><strong>Constraints:</strong></p> |
| 49 | + |
| 50 | +<ul> |
| 51 | + <li><code>1 <= nums.length <= 10<sup>5 </sup></code></li> |
| 52 | + <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> |
| 53 | + <li><code>1 <= modulo <= 10<sup>9</sup></code></li> |
| 54 | + <li><code>0 <= k < modulo</code></li> |
| 55 | +</ul> |
0 commit comments