[EASY TO UNDERSTAND ] Prefix max from the right, prefix min from the right then sum all of them up
Complexity

Time complexity: O(n)


Space complexity: O(n)

Code
# Complexity
- Time complexity: O(n)

- Space complexity: O(n)

# Code
```java []
class Solution {
    public int minimumSum(int[] nums) {
        int N = nums.length;
        int[] prefixSum = new int[N];
        prefixSum[0] = nums[0];
        for (int i = 1; i < N; i++) {
            prefixSum[i] = Math.min(prefixSum[i - 1], nums[i]);
        }

        int[] postfixSum = new int[N];
        postfixSum[N - 1] = nums[N - 1];
        for (int i = N - 2; i >= 0; i--) {
            postfixSum[i] = Math.min(postfixSum[i + 1], nums[i]);
        }

        int best = Integer.MAX_VALUE;
        for (int i = 1; i < N - 1; i++) {
            if (prefixSum[i] < nums[i] && postfixSum[i] < nums[i])
                best = Math.min(prefixSum[i] + postfixSum[i] + nums[i], best);
        }
        return best == Integer.MAX_VALUE ? -1 : best;
    }
}
```
['Array', 'Java']