[DP, O(N^2)] JS Solution
\n/*\nStringtly increasing subsequence of size 3 or \nStrictly decreasing subsequence of size 3 is a valid team.\nWe need to find all such subsequences.\n*/\nva
```\n/*\nStringtly increasing subsequence of size 3 or \nStrictly decreasing subsequence of size 3 is a valid team.\nWe need to find all such subsequences.\n*/\nvar numTeams = function(rating) {\n    // dp1[i] = number of elements less than rating[i] in rating[0...i-1]\n    // dp2[i] = number of elements greater than rating[i] in rating[0...i-1]\n    let dp1 = new Array(rating.length).fill(0);\n    let dp2 = new Array(rating.length).fill(0);\n    let count = 0;\n    for (let i = 0; i < rating.length; i++) {\n        for (let j = 0; j < i; j++) {\n            if (rating[j] < rating[i]) {\n                dp1[i]++;\n                // dp1[j] is the number of elements less than a number, which is less than current number\n                // so, if dp1[j] is 1, (lets\'s say, some number x), then we have a team of (x, rating[j], rating[i])\n                // if dp1[j] is 2, (let\'s say, some number x and y), then we have a team of\n                // (x, rating[j], rating[i]) and (y, rating[j], rating[i])\n                count += dp1[j]; \n            }\n            if (rating[j] > rating[i]) {\n                dp2[i]++;\n                count += dp2[j];\n            }\n        }\n    }\n    return count;\n    // T.C: O(N^2)\n    // S.C: O(N)\n};\n```
['JavaScript']