As reported: Oracle phone interview, Feb 2025 — the first of two questions, with a HackerRank-style signature
triplets(t, d)returning a long.
Given a threshold t and an array d of n distinct integers, count the triplets of indices (a, b, c) such that d[a] < d[b] < d[c] and d[a] + d[b] + d[c] ≤ t.
Because the values are distinct and must increase, each set of three values is counted exactly once.
Example 1
t = 8, d = [1,2,3,4,5]
Output: 4
The triplets of values are (1,2,3), (1,2,4), (1,2,5) and (1,3,4).
Example 2
t = 6, d = [3,2,1]
Output: 1
Constraints: 1 ≤ n ≤ 10^4; 0 ≤ d[i] < 10^9, all distinct; 0 < t < 3·10^9.
Code runner format: one JSON value per line — t, then d. Implement triplets(t, d) returning a 64-bit integer; the harness prints it.