Google Oa question

Posted
20 May 2025
368 reads

Summary

This post details a specific question encountered during a Google Online Assessment (OA).

How it went

Given an integer array nums, a window size windowSize, and an integer k, return a list of averages for each sliding window of size windowSize as the window moves from left to right across the array. When calculating the average for each window, ignore the largest k numbers within that window.

Constraints:

1 <= windowSize <= nums.length <=1e5

0 <= k < windowSize

-1e4<= nums[i] <= 1e4

Example 1:

Input: nums = [10, 20, 30, 40, 50, 60], windowSize = 3, k = 1 Output: [15.0, 25.0, 35.0, 45.0] Explanation:

Window [10, 20, 30]: Ignoring the largest number 30, the average is (10 + 20) / 2 = 15.0 Window [20, 30, 40]: Ignoring the largest number 40, the average is (20 + 30) / 2 = 25.0 Window [30, 40, 50]: Ignoring the largest number 50, the average is (30 + 40) / 2 = 35.0 Window [40, 50, 60]: Ignoring the largest number 60, the average is (40 + 50) / 2 = 45.0 Example 2:

Input: nums = [5, 1, 3, 8, 7], windowSize = 2, k = 0 Output: [3.0, 2.0, 5.5, 7.5]

Example 3:

Input: nums = [4, 4, 4, 4], windowSize = 2, k = 1 Output: [4.0, 4.0, 4.0]

Questions asked (1)

  1. 01

    Sliding Window Average Excluding Largest K Numbers

    Data Structures & Algorithms · Medium

    Given an integer array nums, a window size windowSize, and an integer k, return a list of averages for each sliding window of size windowSize as the window moves from left to right across the array. When calculating the average for each window, ignore the largest k numbers within that window.

    Constraints:

    1 <= windowSize <= nums.length <=1e5

    0 <= k < windowSize

    -1e4<= nums[i] <= 1e4

    Example 1:

    Input: nums = [10, 20, 30, 40, 50, 60], windowSize = 3, k = 1 Output: [15.0, 25.0, 35.0, 45.0] Explanation:

    Window [10, 20, 30]: Ignoring the largest number 30, the average is (10 + 20) / 2 = 15.0 Window [20, 30, 40]: Ignoring the largest number 40, the average is (20 + 30) / 2 = 25.0 Window [30, 40, 50]: Ignoring the largest number 50, the average is (30 + 40) / 2 = 35.0 Window [40, 50, 60]: Ignoring the largest number 60, the average is (40 + 50) / 2 = 45.0 Example 2:

    Input: nums = [5, 1, 3, 8, 7], windowSize = 2, k = 0 Output: [3.0, 2.0, 5.5, 7.5]

    Example 3:

    Input: nums = [4, 4, 4, 4], windowSize = 2, k = 1 Output: [4.0, 4.0, 4.0]

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Google recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

Be the first to share your thoughts and start the discussion!