Simple JAVA solution || LeftCandyArray || RightCandyArray
Intuition\nSimple Left Max Array and Right Max Array\n\n# Approach\n1.First consider at any cost you will distrubute one candy to every child, so take left Max 
# Intuition\nSimple Left Max Array and Right Max Array\n\n# Approach\n1.First consider at any cost you will distrubute one candy to every child, so take left Max Array and store 1 in every index.\n2.Next you start traversing from i=1 to N-1 and checking if the rating of before is greater than current if so you add one to the current.\n\nKeep in Mind that he said both the neighbhours not a single side, so we do the same for right Max Array also\n\nAt last we need to take max of both such that if we pick an index i then for sure if his rating is greater than his neighbours he will be getting more chocolates.\n\n# Complexity\n- Time complexity:\nO(N)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\n    public int candy(int[] ratings) {\n      int N = ratings.length;\n         int[] leftCandy = new int[N];\n        int[] rightCandy=new int[N];\n        Arrays.fill(leftCandy,1);\n        Arrays.fill(rightCandy,1);\n        for(int i=1;i<N;i++){\n            if(ratings[i]>ratings[i-1]){\n                leftCandy[i]=leftCandy[i-1]+1;\n            }\n        }\n        for(int i=N-2;i>=0;i--){\n            if(ratings[i]>ratings[i+1]){\n                rightCandy[i]=rightCandy[i+1]+1;\n            }\n        }\n        int res=0;\n        for(int i=0;i<N;i++){\n            res+=Math.max(leftCandy[i],rightCandy[i]);\n        }\n        return res;\n    }\n}\n```
['Greedy', 'Java']