FastPrepIncreasing-Value Triplets Under a Threshold
Problems/Increasing-Value Triplets Under a Threshold

Increasing-Value Triplets Under a Threshold

IBM logoIBM● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IBM intern online assessment. The report labels the threshold as an int but allows values up to 3 * 10^9. Its caption also adds an original-index-order condition that conflicts with the prompt picture and the sorting hint. Our version uses 64-bit math and orders by value. It is about 96% the same as the reported question.

Given an array of distinct integers d and a threshold t, return the number of triplets of distinct indices (a, b, c) that satisfy both conditions:

  • d[a] < d[b] < d[c].
  • d[a] + d[b] + d[c] <= t.

The indices identify three distinct elements. Their original positions do not need to satisfy a < b < c; the tuple is ordered by the selected values.

Use 64-bit arithmetic for t, each sum, and the returned count.

Implement triplets(long t, int[] d).

Function

triplets(t: long, d: int[]) → long

Examples

Example 1

t = 8d = [1, 2, 3, 4, 5]return = 4

The four valid value triplets are:

  • (1, 2, 3), whose sum is 6.
  • (1, 2, 4), whose sum is 7.
  • (1, 2, 5), whose sum is 8.
  • (1, 3, 4), whose sum is 8.

Example 2

t = 7d = [4, 1, 2]return = 1

The selected values (1, 2, 4) have sum 7. Their original indices are (1, 2, 0), so they count even though those positions are not increasing.

Example 3

t = 2500000000d = [800000000, 800000001, 800000002]return = 1

The only possible triplet sums to 2400000003, which does not exceed 2500000000. The threshold is greater than 2^31 - 1, so it requires a 64-bit type.

Constraints

  • 1 <= d.length <= 10^4.
  • All values in d are distinct.
  • 0 < d[i] < 10^9.
  • 0 < t < 3 * 10^9.

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 Triplets With Sum at Most TargetGoogle · ONSITE INTERVIEWGoogle interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • Sum of Pipeline Response TimesBloomberg LP · OABloomberg LP interview questions
  • Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
  • Count Perfect PairsAdyen · OAAdyen interview questions
  • Profitable Project PairsAkuna Capital · OAAkuna Capital interview questions
  • Stable Robot ConfigurationsAmazon · OA
  • Most Employees Working at OnceCitadel · OACitadel interview questions
  • 3SumAT&T · OAAT&T interview questions
  • Minimum Height Difference Between Distant PeaksRoblox · OARoblox 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 long triplets(long t, int[] d) {
      // Write your code here.
    }
}
Checking account…