Easy C++ Solution || T.C --> O(N) || S.C --> O(N)
Up vote if found useful\n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(N)\n\n# Code\n\nclass Solution {\npublic:\n    int candy(vector<int>& 
**Up vote if found useful**\n\n# Complexity\n- Time complexity: O(N)\n\n- Space complexity: O(N)\n\n# Code\n```\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        vector<int> l (ratings.size(),1);\n        vector<int> r (ratings.size(),1);\n\n        for(int i=1; i<ratings.size(); i++){\n            if(ratings[i]>ratings[i-1]){\n                l[i]=l[i-1]+1;\n            }\n        }\n\n        for(int i = ratings.size()-2; i>=0; i--){\n            if(ratings[i+1]<ratings[i]){\n                r[i]= r[i+1]+1;\n            }\n        }\n        \n        int sum =0;\n        for(int i=0; i<ratings.size();i++){\n            sum+=max(l[i],r[i]);\n        }\n\n        return sum;\n    }\n\n};\n```
['Array', 'Greedy', 'C++']