4ms || Java Solution || Greedy Approach
Time Complexity: O(N)\n\nJava Code\n\n\nimport java.util.*;  \nclass Solution {\n    public int candy(int[] ratings) {\n        int size = ratings.length;\n    
**Time Complexity: O(N)**\n\n**```Java Code```**\n\n```\nimport java.util.*;  \nclass Solution {\n    public int candy(int[] ratings) {\n        int size = ratings.length;\n        int[] left = new int[size];\n        int[] right = new int[size];\n        left[0] = 1;\n        right[size-1] = 1;\n        for(int i = 1; i < size; i++){\n            if(ratings[i] > ratings[i - 1])\n                left[i] = left[i - 1] + 1;\n            else \n                left[i] = 1;\n        }\n        \n        for(int i = size - 2; i >= 0; i--){\n            if(ratings[i] > ratings[i + 1])\n                right[i] = right[i + 1] + 1;\n            else \n                right[i] = 1;\n        }\n        \n        int answer = 0;\n        for(int i = 0; i < size; i++){\n            answer+=Math.max(left[i], right[i]);\n        }\n        \n        return answer;\n    }\n}\n```
['Greedy', 'Java']