2733. Neither Minimum nor Maximum Easy
1/**
2 * [2733] Neither Minimum nor Maximum
3 *
4 * 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.
5 * Return the selected integer.
6 *
7 * <strong class="example">Example 1:
8 *
9 * Input: nums = [3,2,1,4]
10 * Output: 2
11 * Explanation: In this example, the minimum value is 1 and the maximum value is 4. Therefore, either 2 or 3 can be valid answers.
12 *
13 * <strong class="example">Example 2:
14 *
15 * Input: nums = [1,2]
16 * Output: -1
17 * 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.
18 *
19 * <strong class="example">Example 3:
20 *
21 * Input: nums = [2,1,3]
22 * Output: 2
23 * Explanation: Since 2 is neither the maximum nor the minimum value in nums, it is the only valid answer.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= nums.length <= 100
29 * 1 <= nums[i] <= 100
30 * All values in nums are distinct
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/neither-minimum-nor-maximum/
36// discuss: https://leetcode.com/problems/neither-minimum-nor-maximum/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn find_non_min_or_max(nums: Vec<i32>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_2733() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.