leftMin and rightMin, to store the minimum values to the left and right of each index.leftMin by iterating from left to right, ensuring that leftMin[i] contains the minimum value from nums[0] to nums[i-1].rightMin by iterating from right to left, ensuring that rightMin[i] contains the minimum value from nums[i+1] to nums[n-1].minSum to a very large value to track the minimum sum of a mountain triplet.i from 1 to n-2 and check if leftMin[i-1] < nums[i] and rightMin[i+1] < nums[i] to ensure a valid mountain.minSum with the sum of nums[i], leftMin[i-1], and rightMin[i+1] if it is smaller than the current minSum.minSum was updated. If it was not, return -1 to indicate no mountain triplet was found. Otherwise, return minSum.