Simple C++ Array - with descriptions.
Solving using 2 array\nTime complexity : O(n)\nSpace Complexity : O(n)\n\n\nclass Solution {\npublic:\n    int candy(vector<int>& r) {\n        vector<int> a(r.
**Solving using 2 array**\nTime complexity : O(n)\nSpace Complexity : O(n)\n\n```\nclass Solution {\npublic:\n    int candy(vector<int>& r) {\n        vector<int> a(r.size(),0);\n        vector<int> b(r.size(),0);\n        a[0]=1;     // initialising first element with 1\n        for(int i=1;i<r.size();i++){    // stores the candies distribution from left to right\n            if(r[i]>r[i-1]){        // remember equal candies will fetch 1 candy to the child \n                a[i]=a[i-1]+1;\n            }else {\n                a[i]=1;\n            }\n        }\n        b[r.size()-1]=1;    // initialising last element with 1\n        for(int i=r.size()-2;i>=0;i--){  // stores the candies distribution from right to lefr\n            if(r[i]>r[i+1]){    // remember equal candies will fetch 1 candy to the child \n                b[i]=b[i+1]+1;\n            }else {\n                b[i]=1;\n            }\n        }\n        int sum=0;\n        for(int i=0;i<r.size();i++){\n            a[i]=max(a[i],b[i]);    // since we need to distribute such that they get max candies\n            sum+=a[i];\n        }\n        return sum;\n    }\n};\n```
['Array', 'Greedy', 'C++']