Tutte le sfide
Facile 0 risolte 0% di accettazione

Above-Average Values

Keep the values that are greater than the average.

Problema

Compute the average of the list, then keep only the values strictly greater than it, in their original order.

Implement above_average(numbers).

Input

numbers: The list of integers.

Output

Return the values above the average (an empty list for an empty input).

Vincoli

0 ≤ length ≤ 10,000; -1,000,000 ≤ each value ≤ 1,000,000

Esempi

Esempio 1
Input:
numbers = [1, 2, 3, 4, 10]

Output atteso:
expected = [10]
Input:
std::vector<long long> numbers = {1, 2, 3, 4, 10};

Output atteso:
std::vector<long long> expected = {10};
Input:
long[] numbers = new long[] {1, 2, 3, 4, 10};

Output atteso:
long[] expected = new long[] {10};

Spiegazione

The average is 20 / 5 = 4; only 10 is greater than 4.

Esempio 2
Input:
numbers = [5, 5, 5]

Output atteso:
expected = []
Input:
std::vector<long long> numbers = {5, 5, 5};

Output atteso:
std::vector<long long> expected = {};
Input:
long[] numbers = new long[] {5, 5, 5};

Output atteso:
long[] expected = new long[] {};

Spiegazione

Every value equals the average 5, so none is greater: [].

Riferimenti

Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.

Impara dagli altri

Soluzioni della community

Nessuna soluzione pubblicata. Risolvi questa sfida per condividere la prima.