Java Solution 💚💚 | Simple Solution | Easy
Code\n\nclass Solution {\n    public int candy(int[] ratings) {\n        int[] arr = new int[ratings.length];\n        Arrays.fill(arr, 1);\n        int ans = r
# Code\n```\nclass Solution {\n    public int candy(int[] ratings) {\n        int[] arr = new int[ratings.length];\n        Arrays.fill(arr, 1);\n        int ans = ratings.length;\n\n        while(true){\n            boolean bool = false;\n            for(int i = 0; i < ratings.length-1; i++){\n\n                if(ratings[i] > ratings[i+1] && arr[i] <= arr[i+1]){\n                    arr[i]++;\n                    ans++;\n                    bool = true;\n                }\n\n                if(ratings[i] < ratings[i+1] && arr[i] >= arr[i+1]){\n                    arr[i+1]++;\n                    ans++;\n                    bool = true;\n                }\n            }\n\n            if(!bool)\n                break;\n        }\n\n        return ans;\n    }\n}\n// UP-VOTE IF HELPFUL\n```
['Array', 'Greedy', 'Java']