PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Google

Compute sliding-window average excluding top k

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's understanding of sliding-window algorithms, order-statistics maintenance, and data-structure techniques for incremental aggregation when excluding the largest k elements from each window.

  • medium
  • Google
  • Coding & Algorithms
  • Software Engineer

Compute sliding-window average excluding top k

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem You are given an integer array `nums`, a window size `windowSize = w`, and an integer `k`. For every contiguous subarray (window) of length `w` as the window slides from left to right by 1, compute the **average of the elements after removing the largest `k` elements in that window**. More precisely, for each window `nums[i .. i+w-1]`: 1. Identify the `k` largest values in the window (if there are ties, removing any `k` elements among the maximum values is fine). 2. Remove those `k` elements. 3. Compute the arithmetic mean of the remaining `w - k` elements. Return the list of averages in order, one per window. ## Input - `nums`: array of integers - `w`: window size (`1 <= w <= len(nums)`) - `k`: number of largest elements to exclude (`0 <= k < w`) ## Output - An array `ans` of length `len(nums) - w + 1`, where `ans[i]` is the average for window starting at index `i`. ## Notes / Clarifications - Use floating-point averages (do not floor/round unless specified). - Constraints are not provided; propose an algorithm more efficient than recomputing from scratch for each window. ## Example If `w = 3`, `k = 1`, and `nums = [1, 3, 2, 6, 4]`: - Window `[1,3,2]` remove max `3` → average of `[1,2]` = `1.5` - Window `[3,2,6]` remove max `6` → average of `[3,2]` = `2.5` - Window `[2,6,4]` remove max `6` → average of `[2,4]` = `3.0` Return `[1.5, 2.5, 3.0]`.

Quick Answer: This question evaluates a candidate's understanding of sliding-window algorithms, order-statistics maintenance, and data-structure techniques for incremental aggregation when excluding the largest k elements from each window.

Related Interview Questions

  • Solve Rooms and Top-K Streams - Google (medium)
  • Find Containing Range - Google (medium)
  • Rearrange Tasks With Cooldown - Google (medium)
  • Implement Employee Management and Expression Evaluation - Google (medium)
  • Solve Three Array and Matrix Path Problems - Google (medium)
Google logo
Google
Oct 5, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0
Loading...

Problem

You are given an integer array nums, a window size windowSize = w, and an integer k.

For every contiguous subarray (window) of length w as the window slides from left to right by 1, compute the average of the elements after removing the largest k elements in that window.

More precisely, for each window nums[i .. i+w-1]:

  1. Identify the k largest values in the window (if there are ties, removing any k elements among the maximum values is fine).
  2. Remove those k elements.
  3. Compute the arithmetic mean of the remaining w - k elements.

Return the list of averages in order, one per window.

Input

  • nums : array of integers
  • w : window size ( 1 <= w <= len(nums) )
  • k : number of largest elements to exclude ( 0 <= k < w )

Output

  • An array ans of length len(nums) - w + 1 , where ans[i] is the average for window starting at index i .

Notes / Clarifications

  • Use floating-point averages (do not floor/round unless specified).
  • Constraints are not provided; propose an algorithm more efficient than recomputing from scratch for each window.

Example

If w = 3, k = 1, and nums = [1, 3, 2, 6, 4]:

  • Window [1,3,2] remove max 3 → average of [1,2] = 1.5
  • Window [3,2,6] remove max 6 → average of [3,2] = 2.5
  • Window [2,6,4] remove max 6 → average of [2,4] = 3.0 Return [1.5, 2.5, 3.0] .

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Google•More Software Engineer•Google Software Engineer•Google Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.