Ctrl K

Strictly Between the Extremes

Easy
You are given an array values of distinct positive integers. Find the leftmost number that is neither the smallest nor the largest value in the array. If there is no such number, return -1. No sorting is needed: a linear pass is enough.
Example 1
values=[8, 3, 5, 10] → 8

The minimum is 3 and the maximum is 10. Reading left to right, 8 comes first and is neither.

Example 2
values=[4, 9] → -1

Both numbers are extremes, so there is nothing to return.

Example 3
values=[2, 6, 1, 7] → 2

The 2 is not the minimum (there is a 1) and not the maximum, so it is the first fit.

Constraints
  • 1 ≤ len(values) ≤ 100
  • 1 ≤ values[i] ≤ 100
  • All numbers in values are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsMerge Into the Spare Tail EasyThe Candidate With Most Votes EasyDoes Any Value Repeat EasyMake It to Every Meeting EasyThe Lost Ticket Easy
loading Python…
Input
values=[8, 3, 5, 10]
Expected
8

Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.