USING || C++
Code\n\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        vector<vector<int>> v;//make vector for store element of rating with index and
# Code\n```\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        vector<vector<int>> v;//make vector for store element of rating with index and want get fist minimum rating element and give him minimum candy 1\n        for(int i = 0; i < ratings.size(); i++){\n            v.push_back({ratings[i],i});\n        }\n        sort(v.begin(),v.end());\n        int n = ratings.size(),x = 0, k= 0;\n        vector<int> ans(n,0);\n        for(auto &i: v){\n            x = 0;\n            if(i[1]-1>=0&&ratings[i[1]]>ratings[i[1]-1]){//if ith index person have rating >= left person than he desirve more candy compare to left\n                x = max(x,ans[i[1]-1]);\n            }\n            if(i[1]+1 < n&&ratings[i[1]]>ratings[i[1]+1]){//same for right.\n                x = max(x,ans[i[1]+1]);\n            }\n            ans[i[1]] = x+1;//how much candy ith person get\n            k += x+1;//total candy allocated\n        }\n        return k;\n    }\n};\n```
['Array', 'Greedy', 'Sorting', 'C++']