O(n) Soln
Complexity
Time complexity:O(n)

Space complexity:O(n)
Code
# Complexity
- Time complexity:$$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:$$O(n)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```rust []
impl Solution {
    pub fn minimum_sum(nums: Vec<i32>) -> i32 {
        let (mut res, mut lm, mut rm) = (i32::MAX, vec![nums[0]; nums.len()], vec![nums[nums.len() - 1]; nums.len()]);
        for i in 1..nums.len(){ lm[i] = lm[i - 1].min(nums[i]); }
        for i in (0..nums.len() - 1).rev() { rm[i] = rm[i + 1].min(nums[i]); }
        for i in (1..nums.len() - 1) {
            if lm[i - 1] < nums[i] && rm[i + 1] < nums[i] { res = res.min(lm[i - 1] + nums[i] + rm[i + 1]); }
        }
        if res == i32::MAX {-1} else {res}
    }
}
```
``` python []
class Solution:
    def minimumSum(self, nums: List[int]) -> int:
        res, lm, rm = float('inf'), [nums[0]] * len(nums), [nums[len(nums) - 1]] * len(nums)
        
        for i in range(1, len(nums)): lm[i] = min(lm[i - 1], nums[i])
        for i in range(len(nums) - 2, -1, -1): rm[i] = min(rm[i + 1], nums[i])

        for i in range(1, len(nums) - 1):
            if lm[i - 1] < nums[i] and rm[i + 1] < nums[i]: res = min(res, lm[i - 1] + nums[i] + rm[i + 1])
        
        return res if res != float('inf') else -1
```
``` Zig []
const std = @import("std");

pub fn minimum_sum(gpa: std.mem.Allocator, nums: []const i32) i32 {
    var res: i32, var lm: []i32, var rm: []i32 = .{
        std.math.maxInt(i32), 
        gpa.alloc(i32, nums.len) catch unreachable, 
        gpa.alloc(i32, nums.len) catch unreachable
    };
    defer {
        gpa.free(lm);
        gpa.free(rm);
    }

    lm[0] = nums[0];
    rm[nums.len - 1] = nums[nums.len - 1];

    for (1..nums.len) |i| { lm[i] = @min(lm[i - 1], nums[i]); }

    var i:i32 = @intCast(nums.len - 2);
    while (i >= 0) : ( i -= 1) { rm[@intCast(i)] = @min(rm[@intCast(i + 1)], nums[@intCast(i)]); }

    for (1..nums.len - 1) |it| {
        if (lm[it - 1] < nums[it] and rm[it + 1] < nums[it]) { res = @min(res, nums[it] + lm[it - 1] + rm[it + 1]); }
    }
    return if (res == std.math.maxInt(i32))  -1  else  res ;
}

test "lc_2908_tests" {
    const testcases = [_]struct{
        nums: []const i32,
        expected: i32
    }{
        .{
            .nums = &.{8, 6, 1, 5, 3},
            .expected = 9
        },
        .{
            .nums = &.{5, 4, 8, 7, 10, 2},
            .expected = 13
        },
        .{
            .nums = &.{6, 5, 4, 3, 4, 5},
            .expected = -1
        }
    };
    for (testcases) |tc| {
        try std.testing.expectEqual(tc.expected, minimum_sum(std.testing.allocator, tc.nums));
    }
}
```
['Python3', 'Rust']