Easy Solution
Intuition\n\n    set vectors all elements 1 then increases element when traversing \n    through ratings array\n\n# Approach\n Describe your approach to solving
# Intuition\n\n    set vectors all elements 1 then increases element when traversing \n    through ratings array\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n    O(n)\n\n- Space complexity:\n    O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        int n = ratings.size();\n        if(n < 2) return n;\n        int ans = 0;\n        vector<int> vec(n, 1);\n\n        for(int i = 1; i < n; ++i){\n            if(ratings[i] > ratings[i-1]){\n                vec[i] = vec[i-1]+1;\n            }\n        }\n        for(int i = n-1; i > 0; i--){\n            if(ratings[i-1]>ratings[i])\n\t\t\t vec[i-1]=max(vec[i]+1,vec[i-1]);\n        }\n\n        for(int i = 0; i < vec.size(); ++i){\n            ans += vec[i];\n        }\n\n        return ans;\n    }\n};\n```
['C++']