The cost of a stock on each day is given in an array, arr. An investor wants to buy the stocks in triplets such that the sum of the cost for three days is divisible by d. The goal is to find the number of distinct triplets
(i,j,k)
such that
i and the sum
(a[i]+a[]]+a[k])
is divisible by
d
. Example Let arr, prices of stock
=[3,3,4,7,8]
and
d=5
. Following are the triplets whose sum is divisible by
d
(1-based indexing): - Triplet with indices
−(1,2,3)
, sum
=3+3+4
which is equal to 10 - Triplet with indices
−(1,3,5)
, sum
=3+4+8
which is equal to 15 - Triplet with indices
−(2,3,4)
, sum
=3+4+8
which is equal to 15 Hence the answer is 3. Function Description Complete the function getTripletCount in the editor below. The function must return an integer denoting the total number of distinct triplets. getTripletCount has the following parameters: arrD: an array of integers
d:
an integer Constraints -
3≤n≤10 3
-
1≤arrij≤10 9
-
2≤d≤10 6
Input Format For Custom Testing Sample Case 0