In a sealed online auction, n bidders each submit exactly one integer bid; bidders cannot see anyone else's bid, and bid values may repeat. A submitted bid is called sandwiched if, among all of the other submitted bids, at least one is strictly lower than it and at least one is strictly higher than it.
Given the list of submitted bids in the order they were received, count how many of the n bids are sandwiched.
Line 1: an integer n, the number of bids.
Line 2: n space-separated integers, the bids in the order received.
A single integer: the number of sandwiched bids.
Example 1
Input
4 1 2 3 4
Expected
2
Explanation
The bids are 1, 2, 3, 4. Bid 1 has nothing lower, and bid 4 has nothing higher, so neither is sandwiched. Bid 2 has 1 below and 3 (or 4) above; bid 3 has 1 (or 2) below and 4 above. So 2 bids (2 and 3) are sandwiched.
Example 2
Input
3 5 5 5
Expected
0
Explanation
All three bids equal 5. No bid has any other bid strictly lower or strictly higher, so 0 bids are sandwiched.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →