Ctrl K

Neither the Lowest nor the Highest

Easy
You are given a list of integers heights, the heights of some participants. Count how many elements have both a strictly smaller and a strictly larger value somewhere in the list. If a value appears several times, each occurrence is counted separately.
Example 1
heights=[170, 155, 182, 170] → 2

Both 170s are taller than 155 and shorter than 182. The shortest and the tallest do not count.

Example 2
heights=[5, 5, 5] → 0

All values are equal, so nobody has a strictly smaller value in the list.

Example 3
heights=[-2, 0, 9, 4, -2] → 2
Constraints
  • 1 ≤ len(heights) ≤ 10⁵
  • -10⁵ ≤ heights[i] ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyValues One Apart EasyOrder by Set Bits EasyPresent in Every List EasyZeros Before Ones Easy
loading Python…
Input
heights=[170, 155, 182, 170]
Expected
2

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