Given an array of n distinct integers, d = [d[0], d[1], ..., d[n-1]], and an integer threshold t, determine the number of (a, b, c) index triplets that satisfy both the conditions:
d[a] < d[b] < d[c]
d[a] + d[b] + d[c] ≤ t
Example 1:
Input:[8,[1,2,3,4,5]]
Output:4
Example 2:
Input:[8,[1,2,3,4,6]]
Output:3
Example 3:
Input:[7,[3,1,2,4]]
Output:2
Constraints:
1 ≤ n ≤ 10^4
0 ≤ d[i] < 10^9
0 < t < 3 × 10^9
solution.cpp
Loading...
Run code to see test results
00:00 / 69:42
Triplet Sum - Visa DTU
MediumMed•595 views
Given an array of n distinct integers, d = [d[0], d[1], ..., d[n-1]], and an integer threshold t, determine the number of (a, b, c) index triplets that satisfy both the conditions: