#2733
Neither Minimum nor Maximum
newbie · 220 · lc easy +17 · verified · 76.3% accepted · 399 likes · top 87%
Description
You are given an array nums of distinct positive integers. Return any element that is strictly between the minimum and maximum values, or -1 if no such element exists.
Example 1:
Input: nums = [3,2,1,4]
Output: 2
Explanation: In this example, the minimum value is 1 and the maximum value is 4. Therefore, either 2 or 3 can be valid answers.
Example 2:
Input: nums = [1,2]
Output: -1
Explanation: 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.
Example 3:
Input: nums = [2,1,3]
Output: 2
Explanation: Since 2 is neither the maximum nor the minimum value in nums, it is the only valid answer.
Code
1
2
3