Java easy solution with proper explanation(Beats 100%)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. 1.We will make two array 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->1.We will make two array and we will keep each element value as 1 for those two array. Now we will move from left to right and if we found the element to be greater than the neightbouring element, then we will make the value of that index to be 1 greater than the previous index value and store this all value in array named as LtoR\n2.Similarly we will move from right to left (we will start from n-2 element) and compare and do the same thing as mentioned above and store all value in RtoL array.\n3.After that we will make another array named as \'ans\' and store the max value of LtoR and RtoL arrays.\n4.Then we will sum up the value of res and get the final output.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->O(N)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int candy(int[] ratings) {\n        int n = ratings.length;\n        int[] LtoR = new int[n];//LtoR(Left to right)\n        int[] RtoL = new int[n];//RtoL(Right to left)\n        for(int i=0; i<n; i++){\n            LtoR[i]=RtoL[i]=1;// assign each element value as 1\n        }\n        for(int i=1; i<n;i++){\n            if(ratings[i]>ratings[i-1]){\n                LtoR[i]=LtoR[i-1]+1;\n            }\n        }\n        for(int i=n-2; i>=0; i--){\n            if(ratings[i]>ratings[i+1]){\n                RtoL[i]=RtoL[i+1]+1;\n            }\n        }\n        int[] ans = new int[n];\n        int sum =0;\n        for(int i=0; i<n; i++){\n            ans[i] = Math.max(LtoR[i],RtoL[i]);\n            sum += ans[i];\n        }\n        return sum;\n    }\n}\n```
['Greedy', 'Java']