C++ O(n*n) Approach and Code Explanation  , DP permutation
The Idea is to generate the ways the combination can form\nBrute force solution would be to use 3 loop to check the combination O(n^3)\n\nfor(int i=0;i<rating.s
The Idea is to generate the ways the combination can form\nBrute force solution would be to use 3 loop to check the combination O(n^3)\n```\nfor(int i=0;i<rating.size();i++)\n\tfor(int j=0;j<i;j++)\n\t\tfor(int k=0;k<j;k++)\n\t\tcheck for the condition satifying + increase the count\n```\n\n**O(n^2) approach** ,actually use the permutation (DP) to count the ways\nTo satify the condition  rating[i] < rating[j] < rating[k] \n\nTake 2 variable leftless and rightgreat\n\nwe have to count for each rating(pivot) , rating **less than** the left of  **pivot** meaning **leftless** and rating **greater than** right to the **pivot** meaning **rightgreat** and mutliplying  the count gives the permutaion to achieve the condition.\n\nleftless * rightgreat\n\nTake 2 variable leftgreat and rightless\n\nTo *satify the condition * rating[i] > rating[j] > rating[k] \nwe have to count for each rating(pivot) , rating **greater than**  left of the **pivot**  meaning **leftgreat** and rating **less than** right to the **pivot**  meaning **rightless** and mutliplying  the count gives the permutaion to achieve the condition\n\nleftgreat * rightless\nAdd both the results for each index , gives total count\n\n\n```\nclass Solution {\npublic:\n    int numTeams(vector<int>& rating) {\n        \n        int res =0;\n        for(int i= 1;i<=rating.size()-1;i++)\n        {\n            int leftless = 0,leftgreat =0,rightless =0 ,rightgreat =0;\n            \n            for(int j=0;j<rating.size();j++)\n            {\n                if(rating[j]<rating[i])\n                {\n                    if(j<i)\n                    {\n                        //left less\n                        leftless ++;\n                    }\n                    else if(j>i)\n                    {\n                        //right less\n                        rightless++;\n                    }\n                }\n                else if(rating[j]>rating[i])\n                {\n                    if(j<i)\n                    leftgreat++;\n                    else if(j>i)\n                    rightgreat++;\n                }\n            }\n            // [leftless rightgreat] satify rating[i] < rating[j] < rating[k]\n            // [leftgreat,rightless] satify rating[i] > rating[j] > rating[k]\n            //multiply give permutation/way of achieving that condition \n            //adding give the total permutation for each index\n            res += leftless*rightgreat +leftgreat*rightless;\n        }\n        return res;\n    }\n};\n```
['Dynamic Programming']