Skip to main content
Back to problems
#2733
Easy Algorithms

Neither minimum nor maximum

Array Sorting
76.3% acceptance
Feb 25, 2026
398
20
Given an integer array nums containing distinct positive 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.

Solution

Rust
Time O(n log n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn find_non_min_or_max(nums: Vec<i32>) -> i32 {
    if nums.len() < 3 { return -1; }
    let mut v = nums;
    v.sort();
    v[1]
  }
}