Simple Java solution O(n * n)
\nclass Solution {\n    public int numTeams(int[] rating) {\n        int res = 0;\n        int[] greater = new int[rating.length];\n        int[] smaller = new 
```\nclass Solution {\n    public int numTeams(int[] rating) {\n        int res = 0;\n        int[] greater = new int[rating.length];\n        int[] smaller = new int[rating.length];\n        for(int i = 0; i < rating.length - 1; i++){\n            int count1 = 0, count2 = 0;\n            for(int j = i + 1; j < rating.length; j++){\n                if(rating[j] > rating[i]){\n                    count1++;\n                }\n                if(rating[j] < rating[i]){\n                    count2++;\n                }\n            }\n            greater[i] = count1;\n            smaller[i] = count2;\n        }\n        for(int i = 0; i < rating.length - 2; i++){\n            for(int j = i + 1; j < rating.length - 1; j++){\n                if(rating[j] > rating[i]){\n                    res += greater[j];\n                }\n                if(rating[j] < rating[i]){\n                    res += smaller[j];\n                }\n            }\n        }\n        return res;\n    }\n}\n```
[]