public int candy(int[] ratings) {
        int[] left = new int[ratings.length];
        int[] right = new int[ratings.length];

        for(int i = 0; i < ratings.length; i++){
            left[i] = 1;
            if(i > 0 && ratings[i] > ratings[i - 1]){
                left[i] = left[i - 1] + 1;
            }
        }

        for(int j = ratings.length - 1; j >= 0; j--){
            right[j] = 1;
            if(j < ratings.length - 1 && ratings[j] > ratings[j + 1]){
                right[j] = right[j + 1] + 1;
            }
        }

        int min = 0;
        for(int i = 0; i < ratings.length; i++){
            min += Math.max(left[i], right[i]);
        }
        return min;
    }