Ctrl K

Averages of Extreme Pairs

Easy
You are given an integer array values of even length. While the array is not empty, repeat: 1. Remove the smallest number from the array. 2. Remove the largest number from the array. 3. Write down the average of the two removed numbers. If several numbers tie for smallest or largest, you may remove any of them; it does not change the answer. Return how many **distinct** averages you wrote down.
Example 1
values=[7, 2, 9, 4, 6, 1] → 2

Remove 1 and 9, average 5; then 2 and 7, average 4.5; then 4 and 6, average 5. Two distinct averages: 5 and 4.5.

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

Every pair averages to 3.

Example 3
values=[0, 100] → 1
Constraints
  • 2 ≤ len(values) ≤ 100
  • len(values) is even
  • 0 ≤ values[i] ≤ 100
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValues in Both Lists EasyShared Values With Repeats EasyTwice as Much EasyA Number and Its Opposite EasyA Subsequence of One Word Only Medium
loading Python…
Input
values=[7, 2, 9, 4, 6, 1]
Expected
2

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