[C++] USING TWO ARRAYS || EASY TO UNDERSTAND WITH COMMENTS
TIME COMPLEXITY = O(N)\n\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        int ans = 0, n= ratings.size();\n        \n        // it tak
**TIME COMPLEXITY = O(N)**\n```\nclass Solution {\npublic:\n    int candy(vector<int>& ratings) {\n        int ans = 0, n= ratings.size();\n        \n        // it take care about student get more candies than its left neighbor\n        vector<int>L_candy(n,1);\n        for(int i=1; i<n; i++){\n            if(ratings[i]>ratings[i-1] )\n                L_candy[i]=L_candy[i-1]+1;\n        }\n        \n        // it take care about student get more candies than its right neighbor\n        vector<int> R_candy(n,1);\n        for(int i=n-2; i>=0; i--){\n            if(ratings[i]>ratings[i+1] )\n                R_candy[i] = R_candy[i+1]+1;\n        }\n        \n        // here we take the maximum value which satisfy both the left and the right neighbor condition \n        for(int i=0; i<n; i++){\n            ans += max(L_candy[i], R_candy[i]);\n        }\n        return ans;\n    }\n};\n```\nIf you like the post then **upVote!!!**
['Array', 'C']