UberOA #26
Count Elements with at Least One Smaller and One Greater Value
简单可在线判题
考点(AI 标注)原地数组
Given an integer array nums, count how many array elements have both a strictly smaller element and a strictly greater element. This is equivalent to counting the positions that satisfy min(nums) < nums[i] < max(nums); when the same value appears at several positions, every qualifying position is counted.
This site's valid input ranges: 1≤n≤100000, −10^9≤nums[i]≤10^9.
输入格式
The first line contains n; the second line contains n integers nums[i].
输出格式
Output the number of array positions that satisfy min(nums)<nums[i]<max(nums).
样例 1
输入:
3
1 2 3
输出:
1
样例 2
输入:
1
7
输出:
0
样例 3
输入:
2
4 4
输出:
0
样例 4
输入:
4
1 2 2 3
输出:
2
样例 5
输入:
5
-5 -1 -1 0 8
输出:
3
样例 6
输入:
3
-1000000000 0 1000000000
输出:
1
样例 7
输入:
100
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000
输出:
20
样例 8
输入:
4
-9 -8 -7 -6
输出:
2
样例说明
As long as a value is strictly greater than the global minimum and strictly less than the global maximum, it has both a smaller and a greater element. Count all qualifying positions without deduplicating.