Get Triplet Count

Same as LC.2964

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 < j < k and the sum (arr[i]+arr[j]+arr[k]) is divisible by d.

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:

  1. int arr[n]: array of integers
  2. int d: the divisor

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: