Java Solution with Explanation
\nclass Solution {\n    public int numTeams(int[] ratings) {\n        int total = 0;\n        \n        for(int i = 1; i < ratings.length; i++)\n        {\n    
```\nclass Solution {\n    public int numTeams(int[] ratings) {\n        int total = 0;\n        \n        for(int i = 1; i < ratings.length; i++)\n        {\n            // For ascending order -> rating[i] < rating[j] < rating[k]\n            int leftLess = 0;\n            int rightGreater = 0;\n            \n            // For descending order -> rating[i] > rating[j] > rating[k]\n            int leftGreater = 0;\n            int rightLess = 0;\n            \n            // Find the values smaller/greater on the left side of ith element\n            for(int j = 0; j < i; j++)\n            {\n                if(ratings[j] < ratings[i])\n                {\n                    leftLess++;\n                }\n                else\n                {\n                    leftGreater++;\n                }\n            }\n            \n            // Find the values smaller/greater on the right side of ith element\n            for(int j = ratings.length - 1; j > i; j--)\n            {\n                if(ratings[i] < ratings[j])\n                {\n                    rightGreater++;\n                }\n                else\n                {\n                    rightLess++;\n                }\n            }\n            \n            // total number of teams from index i\n            total += leftLess * rightGreater + leftGreater * rightLess;\n        }\n        \n        return total;\n    }\n}\n```
['Java']