Quick Overview

Return every integer that is strictly greater than the overall arithmetic mean. Preserve input order and duplicates while handling negative values and large lists without modifying the source data.

Return Elements Greater Than the Overall Average

Company: Squarepoint

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: HR Screen

# Return Elements Greater Than the Overall Average Implement `above_average(values)`. Compute the arithmetic mean of the entire non-empty integer list, then return a new list containing every input element that is strictly greater than that mean. Preserve the original order and preserve duplicates. Do not modify `values`. ## Function Contract ```python def above_average(values: list[int]) -> list[int]: ... ``` ## Examples - `above_average([1, 2, 3, 4])` returns `[3, 4]` because the mean is `2.5`. - `above_average([5, 5, 5])` returns `[]`. - `above_average([-5, -1, -3])` returns `[-1]` because the mean is `-3`. ## Constraints - `1 <= len(values) <= 200_000` - `-10**9 <= values[i] <= 10**9`

Quick Answer: Return every integer that is strictly greater than the overall arithmetic mean. Preserve input order and duplicates while handling negative values and large lists without modifying the source data.

Implement above_average(values). Compute the mean of the entire non-empty integer list, then return every element strictly greater than that mean. Preserve order and duplicates, do not modify the input, and avoid floating-point comparison.

Constraints

  • 1 <= len(values) <= 200,000
  • -10^9 <= values[i] <= 10^9
  • The input must not be modified.

Examples

Input: ([1],)

Expected Output: []

Explanation: Checks strict comparison against the full-list mean.

Input: ([1, 2, 3, 4],)

Expected Output: [3, 4]

Explanation: Checks strict comparison against the full-list mean.

Hints

  1. Compare value * len(values) with sum(values).
  2. A strict inequality excludes values equal to the mean.

Loading coding console...