C++ || O(n) || Easy Solution || Using Single array
\t// we can not check neighbour directly for any index because if we change that index i according \n\t// to the neighbour i+1 then may be error because index i
\t// we can not check neighbour directly for any index because if we change that index i according \n\t// to the neighbour i+1 then may be error because index i+1 will further depend on index i+2\n\t// so two times traversal will be required \n\n\tclass Solution {\n\tpublic:\n\t\tint candy(vector<int>& ratings) {\n\t\t\tint n=ratings.size();\n\t\t\t  vector<int>ans(n,1);\n\t\t\tfor(int i=1;i<n;i++)\n\t\t\t{\n\t\t\t\tif(ratings[i]>ratings[i-1] && ans[i]<=ans[i-1])\n\t\t\t\t\tans[i]=ans[i-1]+1;\n\t\t\t}\n\t\t\tfor(int i=n-2;i>=0;i--)\n\t\t\t{\n\t\t\t\tif(ratings[i]>ratings[i+1] && ans[i]<=ans[i+1])\n\t\t\t\t\tans[i]=ans[i+1]+1;\n\t\t\t}\n\t\t\treturn accumulate(ans.begin(),ans.end(),0);\n\t\t}\n\t};
['Greedy', 'C']