Company: Wayfair
Difficulty: medium
Optimal Middle Mountain An intern at HackerRank is assigned is finding the optimal middle subsequence . An optimal middle subsequence is the subsequence chosen[] of length 3 chosen from an array arr , such that chosen[0] chosen[2] and that the sum of its elements is the minimum possible. Given an array, return the sum of the values of the optimal middle subsequence. If there is none, return -1. Note: A subsequence of an array is obtained by deleting some (possibly 0) elements from the array without changing the order of the remaining elements. For example, [1, 3] is a subsequence of [1, 2, 3, 4] while [4, 2] is not. Function Description Complete the function getMinimumSum in the editor below. getMinimumSum has the following parameter: int arr[n] : the given array Returns long_int : the sum of the elements in the optimal middle subsequence or -1 Constraints 3 ≤ n ≤ 10 5 1 ≤ arr[i] ≤ 10 3 Example Consider n = 7, arr = [3, 4, 5, 1, 2, 3, 1]. Then, the subsequence [1, 2, 1] can be chosen a