Get Triplet Count
Updated
Problem statement
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
getTripletCount(arr: int[], d: int) → int
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:
int arr[n]: array of integersint d: the divisor
Examples
Example 1
arr = [3, 3, 4, 7, 8]d = 5return = 3
The triplets whose sum is divisible by d are shown.
- 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.
More Point72 interview questions
- Best Time to Buy and Sell Stock IIPHONE SCREEN · Seen Aug 2026
- Find Minimum in a Rotated Sorted ArrayPHONE SCREEN · Seen Aug 2026
- Maximize Array Beauty After DeletionsOA · Seen Aug 2026
- Simulate a Deterministic Finite AutomatonOA · Seen Aug 2026
- Initial Public OfferingOA · Seen Jul 2026
- Test the HypothesisOA · Seen Jul 2026
- Internet Service Provider Monthly ReportOA · Seen Jul 2026
- Server SelectionOA · Seen Jul 2026
- Lexicographically Smallest String After Substring OperationOA · Seen May 2026
- Generate an Optimal Portfolio Trading ReportPHONE SCREEN · Seen Apr 2026
Similar questions at other companies
- Get Triplet CountIBM · OAIBM interview questions
- Count Reverse-Digit PairsVisa · OAVisa interview questions
- Counting Triplets Divisible by DAT&T · OAAT&T interview questions
- Count Overlapping Square PairsRamp · OARamp interview questions
- Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
- Find Valid SET Card TriplesSnowflake · OA · PHONE SCREENSnowflake interview questions
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Stacked Item and Category DiscountsPalantir · OAPalantir interview questions
- Two Tribes from Taller-Person CountsIntuit · OAIntuit interview questions
- Count One-Swap Number PairsCapital One · OACapital One interview questions