Find timestamps where server load exceeds twice the average

Quick Overview

Given server loads at consecutive timestamps, return every index whose load is strictly greater than twice the average of the whole array. The problem tests a linear scan, an exact comparison that avoids floating point error, and careful handling of the strict inequality.

Find timestamps where server load exceeds twice the average

Company: IBM

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

You are given an array `loads` of non-negative integers, where `loads[i]` is the server load at the i-th of a run of consecutive timestamps. Find every index whose load is strictly greater than twice the average load of the whole array. Return those indices in ascending order. If no index qualifies, return an empty list. ### Function Signature ```python def high_load_indices(loads: list[int]) -> list[int]: ``` ### Rules - The average is the sum of all loads divided by the length of the array, taken exactly with no rounding. - The comparison is strict: a load equal to twice the average does not qualify. - Return the qualifying indices in ascending order. ### Constraints - `1 <= len(loads) <= 10^5` - `0 <= loads[i] <= 10^6` ### Examples ```text Input: loads = [10, 5, 3, 50, 2, 8] Output: [3] ``` The loads sum to 78 over 6 values, so the average is 13 and the threshold is 26. Only `loads[3] = 50` is above 26. ```text Input: loads = [1, 1, 1, 1, 1] Output: [] ``` The average is 1 and the threshold is 2. No load exceeds 2. ```text Input: loads = [3, 1, 1, 1] Output: [] ``` The loads sum to 6 over 4 values, so the average is 1.5 and the threshold is 3. `loads[0] = 3` equals the threshold, and equality does not qualify.

Overview: Given server loads at consecutive timestamps, return every index whose load is strictly greater than twice the average of the whole array. The problem tests a linear scan, an exact comparison that avoids floating point error, and careful handling of the strict inequality.

IBM logo
IBM
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

You are given an array loads of non-negative integers, where loads[i] is the server load at the i-th of a run of consecutive timestamps. Find every index whose load is strictly greater than twice the average load of the whole array.

Return those indices in ascending order. If no index qualifies, return an empty list.

Function Signature

def high_load_indices(loads: list[int]) -> list[int]:

Rules

  • The average is the sum of all loads divided by the length of the array, taken exactly with no rounding.
  • The comparison is strict: a load equal to twice the average does not qualify.
  • Return the qualifying indices in ascending order.

Constraints

  • 1 <= len(loads) <= 10^5
  • 0 <= loads[i] <= 10^6

Examples

Input: loads = [10, 5, 3, 50, 2, 8]
Output: [3]

The loads sum to 78 over 6 values, so the average is 13 and the threshold is 26. Only loads[3] = 50 is above 26.

Input: loads = [1, 1, 1, 1, 1]
Output: []

The average is 1 and the threshold is 2. No load exceeds 2.

Input: loads = [3, 1, 1, 1]
Output: []

The loads sum to 6 over 4 values, so the average is 1.5 and the threshold is 3. loads[0] = 3 equals the threshold, and equality does not qualify.