JavaScript, DP O(N^2), BruteForce O(N^3)
Brute Force\n- Time Complexity: O(N^3)\n- Space Complexity: O(1)\njavaScript\n/**\n * @param {number[]} rating\n * @return {number}\n */\nvar numTeams = functio
### Brute Force\n- Time Complexity: O(N^3)\n- Space Complexity: O(1)\n```javaScript\n/**\n * @param {number[]} rating\n * @return {number}\n */\nvar numTeams = function(rating) {\n    let y = 0;\n    for (let i = 0; i + 2 < rating.length; i++) {\n        for (let j = i + 1; j + 1 < rating.length; j++) {\n            for (let k = j + 1; k < rating.length; k++) {\n                if (rating[i] < rating[j] && rating[j] < rating[k]) y++;\n                if (rating[i] > rating[j] && rating[j] > rating[k]) y++;\n            }\n        }\n    }\n    return y;\n};\n```\n### DP\n- Time Complexity: O(N^2)\n- Space Complexity: O(N)\n```JavaScript\n/**\n * @param {number[]} rating\n * @return {number}\n */\nvar numTeams = function(rating) {\n    const des = new Array(rating.length).fill(0),\n          asc = new Array(rating.length).fill(0);\n    for (let i = rating.length - 2; 0 <= i; i--) {\n        for (let j = i + 1; j < rating.length; j++) {\n            if (rating[i] > rating[j]) {\n                des[i]++;\n            }\n            if (rating[i] < rating[j]) {\n                asc[i]++;\n            }\n        }\n    }\n    let y = 0;\n    for (let i = 0; i + 2 < rating.length; i++) {\n        for (let j = i + 1; j + 1 < rating.length; j++) {\n            if (rating[i] > rating[j]) {\n                y += des[j];\n            }\n            if (rating[i] < rating[j]) {\n                y += asc[j]\n            }\n        }\n    }\n    return y;\n};\n```
['JavaScript']