FastPrepLargest Value in Every Sliding Window
Problems/Largest Value in Every Sliding Window

Largest Value in Every Sliding Window

Adobe logoAdobe● HardFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This was the coding question in the first round of a full-stack interview, after a talk about past projects. The report gives only the problem's name: the largest value in every window of fixed size as it slides along an array.

It gives no limits or examples. Here the array has 1 to 10^4 values from -10^4 to 10^4, the window size is from 1 to the array length, and the examples are our own.

The judged task matches the report at about 95%.

You are given an integer array nums and a window size k. A window is k values next to each other. It starts over the first k values and slides one place to the right at a time until it covers the last value.

Return the largest value inside each window, in order from the leftmost window to the rightmost. There are nums.length - k + 1 windows.

Function

windowMaximums(nums: int[], k: int) → int[]

Examples

Example 1

nums = [2,7,3,1,5,4,6]k = 3return = [7,7,5,5,6]

The five windows are [2, 7, 3], [7, 3, 1], [3, 1, 5], [1, 5, 4] and [5, 4, 6]. Their largest values are 7, 7, 5, 5 and 6.

Example 2

nums = [5,4,3,2,1]k = 2return = [5,4,3,2]

The values only go down, so each window's largest value is its first one: 5, 4, 3 and 2.

Example 3

nums = [-3,-9,-1]k = 3return = [-1]

The window is the whole array, so there is one answer: the largest value, -1.

Constraints

  • 1 <= nums.length <= 10^4
  • -10^4 <= nums[i] <= 10^4
  • 1 <= k <= nums.length

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int[] windowMaximums(int[] nums, int k) {
    // Write your code here.
}
Checking account…