A satellite telemetry stream reports n integer samples in order. Count the number of triples of positions (i, j, k) with i < j < k such that sample[i] < sample[j] < sample[k] — that is, the number of strictly increasing subsequences of length exactly three. Two triples are different if they use different sets of positions (values may repeat).
Line 1: an integer n.
Line 2: n space-separated integers, the samples in order.
A single integer: the count of strictly increasing length-3 subsequences.
Example 1
Input
5 1 2 3 4 5
Expected
10
Explanation
Every choice of 3 of the 5 strictly increasing samples works, and there are 10 such choices.
Example 2
Input
4 5 3 4 1
Expected
0
Explanation
No position triple i<j<k has strictly increasing values, so the count is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →