Easy to understand DP solution || Java
\nclass Solution {\n    public int numTeams(int[] rating) {\n         int len = rating.length;\n\n\t\tint[] up = new int[len]; \n\t\tint[] down = new int[len];\
```\nclass Solution {\n    public int numTeams(int[] rating) {\n         int len = rating.length;\n\n\t\tint[] up = new int[len]; \n\t\tint[] down = new int[len];\n\n\t\tint count = 0;\n        \n        // first <r[i] <r[j] <r[k] order\n        \n        for(int i = 0; i < len; i++){\n            for(int j = i; j >= 0; j--){\n                if(rating[i] > rating[j]){\n                    up[i]++;\n                    count = count + up[j];\n                }\n            }\n        }\n        \n        // second >r[i] >r[j] >r[k] order\n\t\t for(int i = 0; i < len; i++){\n            for(int j = i; j >= 0; j--){\n\t\t\t\tif (rating[i] < rating[j]) {\n\t\t\t\t\tdown[i] += 1;\n\t\t\t\t\tcount += down[j];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn count;\n    }\n}\n```
['Dynamic Programming', 'Java']