Get Triplet Count
Updated
Problem statement
The integer array arr gives a stock’s cost on each day. You are also given an integer d. Count the triplets of indices (i, j, k) with i < j < k where (arr[i] + arr[j] + arr[k]) is divisible by d.
Return how many such triplets there are. Equal values at different indices count as different choices.
Function
getTripletCount(arr: int[], d: int) → intExamples
Example 1
arr = [3, 3, 4, 7, 8]d = 5return = 3These triplets have a sum divisible by d:
- Indices (0, 1, 2): sum = 3 + 3 + 4 = 10.
- Indices (0, 2, 4): sum = 3 + 4 + 8 = 15.
- Indices (1, 2, 4): sum = 3 + 4 + 8 = 15.
No other triplet works, so the answer is 3.
Constraints
3 <= arr.length <= 2000.-10^9 <= arr[i] <= 10^9.1 <= d <= 10^9.- The answer fits in a signed 32-bit integer.
More IBM Online Assessment questions
- Missing IntervalsOA · Seen Nov 2026
- Last Object Exit TimeOA · Seen Nov 2026
- Count Peaks and ValleysOA · Seen Nov 2026
- Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
- Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
- Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
- Maximum Easy Tasks After RearrangingOA · Seen Nov 2026
- Tree Pythagorean TriplesOA · Seen Oct 2026
- Minimum Power-of-Two Removal OperationsOA · Seen Oct 2026
- Maximum Compatible Time WindowsOA · Seen Oct 2026
Similar questions at other companies
- Count Reverse-Digit PairsVisa · OAVisa interview questions
- Get Triplet CountPoint72 · OAPoint72 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