Sliding Window Maximum
Updated
Problem statement
You are given an integer array values and an integer window length k. For each complete contiguous window of k elements, return its maximum value.
The first window contains indices 0 through k-1. Shift it one index to the right each time until the final window ends at values.length-1. Return exactly values.length-k+1 maxima in the same order as the window starts.
Only complete windows count. These are windows of array indices, with no timestamps or variable time widths. Return only maximum values, so equal values need no index tie-breaking rule. Negative values are allowed, and a window maximum may be negative.
Do not change values. Use fresh local state and return a new array for each call. All values and comparisons are exact integers.
Function
slidingWindowMaximum(values: int[], k: int) → int[]Examples
Example 1
values = [4,1,3,5,2,6]k = 3return = [4,5,5,6]The complete windows are [4,1,3], [1,3,5], [3,5,2] and [5,2,6]. Their maxima are 4,5,5,6, in that order.
Example 2
values = [-2,-5,-1,-4]k = 2return = [-2,-1,-1]The windows [-2,-5], [-5,-1] and [-1,-4] have maxima -2,-1,-1. A negative maximum is valid.
Example 3
values = [3,3,1,3]k = 2return = [3,3,3]Each complete pair contains a value equal to 3, so the three window maxima are [3,3,3]. Only values are returned, so the tied indices need no rule.
Constraints
1 <= values.length <= 100.- Every element of
valuesis an integer between-1000000and1000000, inclusive. kis an integer with1 <= k <= 100andk <= values.length.
More Akuna Capital Phone Screen questions
- Match Orders by Price and Arrival TimeOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Biased Coin: Probability of Exactly h HeadsPHONE SCREEN · Seen Nov 2026
- Positive Nth Root with Gradient DescentPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Sep 2026
- Maximum Value in a Binary TreePHONE SCREEN · Seen Sep 2026
- Tiered Expiring Item StorePHONE SCREEN · Seen Aug 2026
- Statistics for the Latest K ValuesPHONE SCREEN · Seen Nov 2025
- Remove Duplicates While Preserving OrderPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025
- Evaluate a PolynomialPHONE SCREEN · Seen Oct 2025
- Reverse Nodes in Groups of KPHONE SCREEN · Seen Oct 2025
Similar questions at other companies
- Disk Space Window AnalyzerAgoda · PHONE SCREENAgoda interview questions
- Longest Continuous Subarray Within an Absolute-Difference LimitOracle · PHONE SCREENOracle interview questions
- Transcript Window MetricsSesame · PHONE SCREEN
- Sliding Window MaximumGroww · PHONE SCREEN
- Largest Value in Every Sliding WindowAdobe · PHONE SCREENAdobe interview questions
- Sliding Window MaximumBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Sliding Window Average (Meta Canada, E4/E5 :)Meta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Sliding Window MaximumNVIDIA · PHONE SCREENNVIDIA interview questions
- Longest Subarray Within an Absolute-Difference LimitGoogle · ONSITE INTERVIEWGoogle interview questions
- Longest Continuous Subarray Within an Absolute-Difference LimitUber · ONSITE INTERVIEWUber interview questions
Interview reports that mention this question
Akuna Capital interview experiences
- Akuna Capital JQR CodePair Rounds: 8 Experiences (Part 6 of 6)
- Akuna Capital QR Probability Phones: 14 Experiences (Part 5 of 6)
- Akuna Capital QR-ML Interviews: 11 Experiences (Part 4 of 6)
- Akuna Capital QR Regression Rounds: 11 Experiences (Part 3 of 6)
- Akuna Capital QR Coding Interviews: 17 Experiences (Part 2 of 6)