Get Triplet Count
Function Description
Complete the function getTripletCount
in the editor below. The function must return an integer denoting the total number of distinct triplets.
def getTripletCount(arr, d):
# implementation
Parameters
int arr[n]
: array of integersint d
: the divisor
Example 1
Input
arr = [3, 3, 4, 7, 8]
d = 5
Output
3
Explanation
Triplets whose sum is divisible by d
:
- Triplet with indices (0, 1, 2), sum = 3 + 3 + 4 = 10
- Triplet with indices (0, 2, 4), sum = 3 + 4 + 8 = 15
- Triplet with indices (1, 2, 4), sum = 3 + 4 + 8 = 15
Hence, the answer is 3
.
我们长期稳定承接各大科技公司如TikTok、Google、Amazon等的OA笔试代写服务,确保满分通过。如有需求,请随时联系我们。
We consistently provide professional online assessment services for major tech companies like TikTok, Google, and Amazon, guaranteeing perfect scores. Feel free to contact us if you're interested.
