simple solution using min heap || C++
\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        int n = ratings.size();\n        vector<int> ans(n,1);\n        priority_queue<pair<
```\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        int n = ratings.size();\n        vector<int> ans(n,1);\n        priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> qe;\n        for(int i = 0 ; i < n ; i++){\n            qe.push({ratings[i],i});\n        }\n        while(!qe.empty()){\n            auto it = qe.top();\n            qe.pop();\n            if(it.second > 0 && ratings[it.second-1] > ratings[it.second])\n                ans[it.second-1] = max(ans[it.second-1],ans[it.second]+1);\n            if(it.second < n-1 && ratings[it.second+1] > ratings[it.second])\n                ans[it.second+1] = max(ans[it.second+1],ans[it.second]+1);\n        }\n        int x = 0;\n        for(auto &it : ans)\n            x += it;\n        return x;\n    }\n};\n```
['C', 'Heap (Priority Queue)']