You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>d</code>, return <em>the number of triplets</em> <code>(i, j, k)</code> <em>such that</em> <code>i < j < k</code> <em>and</em> <code>(nums[i] + nums[j] + nums[k]) % d == 0</code>.
10
+
11
+
<p> </p>
12
+
<p><strongclass="example">Example 1:</strong></p>
13
+
14
+
<pre>
15
+
<strong>Input:</strong> nums = [3,3,4,7,8], d = 5
16
+
<strong>Output:</strong> 3
17
+
<strong>Explanation:</strong> The triplets which are divisible by 5 are: (0, 1, 2), (0, 2, 4), (1, 2, 4).
18
+
It can be shown that no other triplet is divisible by 5. Hence, the answer is 3.
19
+
</pre>
20
+
21
+
<p><strongclass="example">Example 2:</strong></p>
22
+
23
+
<pre>
24
+
<strong>Input:</strong> nums = [3,3,3,3], d = 3
25
+
<strong>Output:</strong> 4
26
+
<strong>Explanation:</strong> Any triplet chosen here has a sum of 9, which is divisible by 3. Hence, the answer is the total number of triplets which is 4.
27
+
</pre>
28
+
29
+
<p><strongclass="example">Example 3:</strong></p>
30
+
31
+
<pre>
32
+
<strong>Input:</strong> nums = [3,3,3,3], d = 6
33
+
<strong>Output:</strong> 0
34
+
<strong>Explanation:</strong> Any triplet chosen here has a sum of 9, which is not divisible by 6. Hence, the answer is 0.
Given a <strong>0-indexed</strong> integer array <code>nums</code> and an integer <code>d</code>, return <em>the number of triplets</em> <code>(i, j, k)</code> <em>such that</em> <code>i < j < k</code> <em>and</em> <code>(nums[i] + nums[j] + nums[k]) % d == 0</code>.
8
+
9
+
<p> </p>
10
+
<p><strongclass="example">Example 1:</strong></p>
11
+
12
+
<pre>
13
+
<strong>Input:</strong> nums = [3,3,4,7,8], d = 5
14
+
<strong>Output:</strong> 3
15
+
<strong>Explanation:</strong> The triplets which are divisible by 5 are: (0, 1, 2), (0, 2, 4), (1, 2, 4).
16
+
It can be shown that no other triplet is divisible by 5. Hence, the answer is 3.
17
+
</pre>
18
+
19
+
<p><strongclass="example">Example 2:</strong></p>
20
+
21
+
<pre>
22
+
<strong>Input:</strong> nums = [3,3,3,3], d = 3
23
+
<strong>Output:</strong> 4
24
+
<strong>Explanation:</strong> Any triplet chosen here has a sum of 9, which is divisible by 3. Hence, the answer is the total number of triplets which is 4.
25
+
</pre>
26
+
27
+
<p><strongclass="example">Example 3:</strong></p>
28
+
29
+
<pre>
30
+
<strong>Input:</strong> nums = [3,3,3,3], d = 6
31
+
<strong>Output:</strong> 0
32
+
<strong>Explanation:</strong> Any triplet chosen here has a sum of 9, which is not divisible by 6. Hence, the answer is 0.
| 2952 | [Minimum Number of Coins to be Added](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README_EN.md) | `Greedy`,`Array`,`Sorting` | Hard | Weekly Contest 374 |
| 2952 | [Minimum Number of Coins to be Added](/solution/2900-2999/2952.Minimum%20Number%20of%20Coins%20to%20be%20Added/README_EN.md) | `Greedy`,`Array`,`Sorting` | Medium | Weekly Contest 374 |
| 2954 | [Count the Number of Infection Sequences](/solution/2900-2999/2954.Count%20the%20Number%20of%20Infection%20Sequences/README_EN.md) | `Array`,`Math`,`Combinatorics` | Hard | Weekly Contest 374 |
2966
-
| 2955 | [Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README_EN.md) | | Medium | 🔒 |
2967
-
| 2956 | [Find Common Elements Between Two Arrays](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md) | | Easy | Biweekly Contest 119 |
| 2958 | [Length of Longest Subarray With at Most K Frequency](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README_EN.md) | | Medium | Biweekly Contest 119 |
2970
-
| 2959 | [Number of Possible Sets of Closing Branches](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README_EN.md) | | Hard | Biweekly Contest 119 |
2971
-
| 2960 | [Count Tested Devices After Test Operations](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README_EN.md) | | Easy | Weekly Contest 375 |
| 2962 | [Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md) | | Medium | Weekly Contest 375 |
2974
-
| 2963 | [Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md) | | Hard | Weekly Contest 375 |
2966
+
| 2955 | [Number of Same-End Substrings](/solution/2900-2999/2955.Number%20of%20Same-End%20Substrings/README_EN.md) | `Array`,`Hash Table`,`String`,`Counting`,`Prefix Sum` | Medium | 🔒 |
2967
+
| 2956 | [Find Common Elements Between Two Arrays](/solution/2900-2999/2956.Find%20Common%20Elements%20Between%20Two%20Arrays/README_EN.md) | `Array`,`Hash Table` | Easy | Biweekly Contest 119 |
| 2958 | [Length of Longest Subarray With at Most K Frequency](/solution/2900-2999/2958.Length%20of%20Longest%20Subarray%20With%20at%20Most%20K%20Frequency/README_EN.md) | `Array`,`Hash Table`,`Sliding Window` | Medium | Biweekly Contest 119 |
2970
+
| 2959 | [Number of Possible Sets of Closing Branches](/solution/2900-2999/2959.Number%20of%20Possible%20Sets%20of%20Closing%20Branches/README_EN.md) | `Bit Manipulation`,`Graph`,`Enumeration`,`Shortest Path`,`Heap (Priority Queue)` | Hard | Biweekly Contest 119 |
2971
+
| 2960 | [Count Tested Devices After Test Operations](/solution/2900-2999/2960.Count%20Tested%20Devices%20After%20Test%20Operations/README_EN.md) | `Array`,`Simulation` | Easy | Weekly Contest 375 |
| 2962 | [Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md) | `Array`,`Sliding Window` | Medium | Weekly Contest 375 |
2974
+
| 2963 | [Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md) | `Array`,`Hash Table`,`Math`,`Combinatorics` | Hard | Weekly Contest 375 |
2975
+
| 2964 | [Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README_EN.md) | | Medium | 🔒 |
- [2962.Count Subarrays Where Max Element Appears at Least K Times](/solution/2900-2999/2962.Count%20Subarrays%20Where%20Max%20Element%20Appears%20at%20Least%20K%20Times/README_EN.md)
3023
3023
- [2963.Count the Number of Good Partitions](/solution/2900-2999/2963.Count%20the%20Number%20of%20Good%20Partitions/README_EN.md)
3024
+
- [2964.Number of Divisible Triplet Sums](/solution/2900-2999/2964.Number%20of%20Divisible%20Triplet%20Sums/README_EN.md)
0 commit comments