Skip to content

2733. Neither Minimum nor Maximum 👍

  • Time: $O(1)$
  • Space: $O(1)$
1
2
3
4
5
6
7
8
9
class Solution {
 public:
  int findNonMinOrMax(vector<int>& nums) {
    if (nums.size() < 3)
      return -1;
    sort(nums.begin(), nums.begin() + 3);
    return nums[1];
  }
};
1
2
3
4
5
6
7
8
class Solution {
  public int findNonMinOrMax(int[] nums) {
    if (nums.length < 3)
      return -1;
    Arrays.sort(nums, 0, 3);
    return nums[1];
  }
}
1
2
3
class Solution:
  def findNonMinOrMax(self, nums: list[int]) -> int:
    return -1 if len(nums) < 3 else sorted(nums[:3])[1]