Leetcode Problem 2733. Neither Minimum nor Maximum

2733. Neither Minimum nor Maximum

Leetcode Solutions

Iterative Comparison Approach

  1. Check if the length of the array is less than 3. If so, return -1.
  2. Initialize two variables to store the minimum and maximum values, setting them both to the first element of the array.
  3. Iterate through the array starting from the second element, updating the minimum and maximum variables as needed.
  4. Iterate through the array again, looking for an element that is not equal to the minimum or maximum values.
  5. If such an element is found, return it.
  6. If no such element is found (which should not happen given the problem constraints), return -1.
UML Thumbnail

Sorting Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...