Given an integer array nums containing distinctpositive integers, find and return any number from the array that is neither the minimum nor the maximum value in the array, or -1 if there is no such number.
Input: nums =[3,2,1,4]Output: 2Explanation: In this example, the minimum value is1 and the maximum value is4. Therefore, either 2 or 3 can be valid answers.
Input: nums =[1,2]Output: -1Explanation: Since there is no number in nums that is neither the maximum nor the minimum, we cannot select a number that satisfies the given condition. Therefore, there is no answer.
intfindNonMinOrMax(vector<int>& nums) {
if (nums.size() <3) return-1;
int mn =*min_element(nums.begin(), nums.end());
int mx =*max_element(nums.begin(), nums.end());
for (int x : nums) if (x != mn && x != mx) return x;
return-1;
}