C++ || Greedy + Intuition Based
Intuition\n Describe your first thoughts on how to solve this problem. \nGREEDYYYYYY !!!!\n\n# Approach\n Describe your approach to solving the problem. \n\nFor
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGREEDYYYYYY !!!!\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nFor an index to form a team : \n  one element smaller in left + curr element +  one element larger in right\n OR\n  one element larger in left + curr element +  one element smaller in right\n\n\nAnd, we have to find the number of smaller & larger elememts in Left of a certain element AND the number of smaller & larger elememts in Right of a certain element.\n\n\n\nKeeping the above in consideration , we can say the number of teams we can form using a current index will be =>\n\ncurr_idx_teams = (left_smaller*right_larger) + (left_larger*right_smaller)\n\n\nDo this over each element and thus obtaining the number of teams possible with each index and add them to get the total.\n\n\n![download (2).jfif](https://assets.leetcode.com/users/images/578fefca-413c-40b1-ac23-40e03909aba4_1680853407.4647636.jpeg)\n\n\n\n# Complexity\n- Time complexity : O(N*N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity  : O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int numTeams(vector<int>& rating) {\n        int n = rating.size();\n        int total_teams = 0;\n\n        for(int idx=0; idx<n; idx++) {\n\n            int left_smaller=0, left_larger=0, right_smaller=0, right_larger=0;\n\n            for(int l=idx-1; l>=0; l--)  {\n                if(rating[l]<rating[idx])   {\n                    left_smaller++;\n                }\n                else {\n                    left_larger++;\n                }\n            }\n\n            for(int r=idx+1; r<n; r++)  {\n                if(rating[r]<rating[idx])   {\n                    right_smaller++;\n                }\n                else {\n                    right_larger++;\n                }\n            }\n\n\n            int curr_idx_teams = (left_smaller*right_larger) + (left_larger*right_smaller);\n\n            total_teams += curr_idx_teams;\n        }\n\n        return total_teams;\n    }\n};\n```
['Dynamic Programming', 'Greedy', 'C++']