☕ Java solution ✅ || 😼 Beats 96.50% ✨
\n\njava []\nclass Solution {\n    public int minimumSum(int[] x) {\n        int min = Integer.MAX_VALUE;\n        for (int i = 1; i < x.length - 1; i++) {\n   
![Screenshot_3.png](https://assets.leetcode.com/users/images/066de30a-08c5-4a37-a2d9-b1e56e6de513_1727579558.285899.png)\n\n```java []\nclass Solution {\n    public int minimumSum(int[] x) {\n        int min = Integer.MAX_VALUE;\n        for (int i = 1; i < x.length - 1; i++) {\n            int leftIdx = i - 1, rightIdx = i + 1, leftVal = x[i], rightVal = x[i], total = 0;\n            boolean leftFound = false, rightFound = false;\n            while (leftIdx > -1) {\n                if (x[leftIdx] < leftVal) {\n                    leftVal = x[leftIdx];\n                    leftFound = true;\n                }\n                leftIdx--;\n            }\n            while (rightIdx < x.length && leftFound) {\n                if (x[rightIdx] < rightVal) {\n                    rightVal = x[rightIdx];\n                    rightFound = true;\n                }\n                rightIdx++;\n            }\n            if (rightFound) {\n                total = leftVal + rightVal + x[i];\n                min = Math.min(min, total);\n            }\n        }\n        return min == Integer.MAX_VALUE ? -1 : min;\n    }\n}\n\n```
['Java']