Java 2 ms DP
\n//build up array and down array i.e the number of up and down element for current point \n//add up triplet counts\npublic int numTeams(int[] rating) {\n      
```\n//build up array and down array i.e the number of up and down element for current point \n//add up triplet counts\npublic int numTeams(int[] rating) {\n      \n        int n = rating.length;\n\n\t\tint[] up = new int[n];\n\t\tint[] down = new int[n];\n\n\t\tint teams = 0;\n\n\t\tfor (int i = n - 1; i >= 0; i--) {\n\t\t\tfor (int j = i + 1; j < n; j++) {\n\t\t\t\tif (rating[i] < rating[j]) {\n\t\t\t\t\tup[i] += 1;\n\t\t\t\t\tteams += up[j];\n\t\t\t\t} else {\n\t\t\t\t\tdown[i] += 1;\n\t\t\t\t\tteams += down[j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn teams;\n    }\n\t\n\t\n```
[]