FastPrepGet Triplet Count
Problems/Get Triplet Count

Get Triplet Count

IBM logoIBM● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A community member reported this exact exercise for IBM on October 8, 2026. That is the date the report was submitted, because no interview date or test platform was given. The report did not include its own prompt wording. So this version reuses the independently reviewed, runnable setup of the matching exercise. It is about 100% the same as the reported matching exercise. The original IBM wording was not available.

Special thanks: 🌷 A special thank you to our lovely, amazing frenz who shared that this question appeared again on October 8, 2026! ( ᴗ͈ˬᴗ͈)ഒ 🧡

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) → int

Examples

Example 1

arr = [3, 3, 4, 7, 8]d = 5return = 3

These 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

IBM interview experiences

  • IBM Full-Time SWE OA Questions: 1 Experience
  • IBM Software Intern Résumé Rounds: 2 Experiences (Part 3 of 3)
  • IBM Intern Blitz Interviews: 23 Experiences (Part 2 of 3)
  • IBM Software Intern Interviews: 44 Experiences (Part 1 of 3)
  • IBM Software Intern Interview Questions: 15 Experiences
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int getTripletCount(int[] arr, int d) {
      // Write your code here.
    }

}
Checking account…