C++ | O(n^2) | w/ comments
\nclass Solution {\npublic:\n    \n    // For soldiers 1 to n-1\n    //   For soldiers 0 to n\n    //      We will keep track these things:\n    //      a = Cou
```\nclass Solution {\npublic:\n    \n    // For soldiers 1 to n-1\n    //   For soldiers 0 to n\n    //      We will keep track these things:\n    //      a = Count of ratings less than current on the left\n    //      b = Count of ratings less than current on the right\n    //      c = Count of ratings more than current on the left\n    //      d = Count of ratings more than current on the right\n\t//   With current soldier in the "center" of the team:\n\t//   We can have (a * d) teams with rating increasing from left to right\n\t//   and (c * b) teams with rating decreasing from left to right\n    //   So the total number is ((a * d) + (c * b)) teams\n    \n    int numTeams(vector<int>& rating) {\n        int teams = 0; // Total number of teams\n        for(int i = 1; i < rating.size() - 1; ++i) {\n            int a = 0, b = 0, c = 0, d = 0;\n            for(int j = 0; j < rating.size(); ++j) {\n                if(j < i) {\n                    if(rating[j] < rating[i]) a++;\n                    if(rating[j] > rating[i]) c++;\n                } else if(j > i) {\n                    if(rating[j] < rating[i]) b++;\n                    if(rating[j] > rating[i]) d++;\n                } else continue;\n            }\n            teams += ((a * d) + (c * b));\n        }\n        return teams;\n    }\n```
[]