scores[i]; all ratings are distinct. A coach builds trios by taking three entrants at positions i < j < k (their order in the row is kept).
A trio works if its ratings strictly increase (scores[i] < scores[j] < scores[k]) or strictly decrease (scores[i] > scores[j] > scores[k]).
Return the number of trios that work. One entrant may belong to several trios.scores=[5, 1, 4, 2, 6] → 3
The trios (1, 4, 6) and (1, 2, 6) strictly increase and (5, 4, 2) strictly decreases, 3 in total.
scores=[6, 5, 4, 3] → 4
Any three entrants are in decreasing order, and there are 4 ways to choose three out of four.
scores=[1, 3, 2] → 0
scores are distinctscores=[5, 1, 4, 2, 6]
3
Run checks the first 3 tests in your browser. Submit checks all 113 tests on the server, hidden ones included.