C++: Simple backtracking
\nint count;\n    \n    void backtrack(vector<int> & rating, int start, int end, vector<int> & arr){\n        if( (arr.size() == 3 && arr[0] < arr[1] && arr[1] 
```\nint count;\n    \n    void backtrack(vector<int> & rating, int start, int end, vector<int> & arr){\n        if( (arr.size() == 3 && arr[0] < arr[1] && arr[1] < arr[2]) || (arr.size() == 3 && arr[0] > arr[1] && arr[1] > arr[2])){\n            count++;\n            return;\n        }\n        if(arr.size() < 3)\n            for (int i=start;i<=end;i++){\n                arr.push_back(rating[i]);\n                backtrack(rating, i+1, end, arr);\n                arr.pop_back();\n\n            }\n    }\n    \n    int numTeams(vector<int>& rating) {\n        count = 0;\n        vector<int> arr;\n        backtrack(rating, 0, rating.size()-1, arr);\n        return count;\n    }\n```
[]