C++ || simple approach || O(n) || easy to undersatand
\n\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        vector<int> num(ratings.size(),1);\n //  if only one element then just return the 
\n```\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        vector<int> num(ratings.size(),1);\n //  if only one element then just return the size\n        \n        if(ratings.size()<=1)\n            return ratings.size();\n        \n       /* The first loop makes sure children with a higher rating get more candy than its left neighbor \n       */   \n        \n        for(int i=0;i<ratings.size()-1;i++)\n        {\n            if(ratings[i]<ratings[i+1])\n                num[i+1]=num[i]+1;\n        }\n        \n      /*  the second loop makes sure children with a higher rating get more candy than its right neighbor\n      to increase */\n        \n        for(int i=ratings.size()-1;i>0;i--)\n        {\n            if(ratings[i-1]>ratings[i])\n                // make sure that the increase in candies is minimum\n                num[i-1]=max(num[i]+1,num[i-1]); \n        }\n        /*   sum the array formed and return it  \n        */\n        return accumulate(num.begin(),num.end(),0);\n    }\n};\n```
['Greedy', 'C']