Skip to the selected question
ASIC.FYI

ASIC Interview Question Bank

1,000+ hardware interview questions.Curated and reviewed by industry engineers.1,000+ hardware questions1,000+ questionsEngineer-reviewed
DescriptionQ233
Page ↗
Q233FWFollow-up to Q232ASIC interview problem

Trailing sliding window maximum

TechniquesSystemVerilogSliding windowMonotonic dequeForward traversal
DifficultyMedium
TopicArrays
LanguageSystemVerilog
Requirements4 checkpoints
01

Problem

Change the window direction: for every index i, compute the maximum from a[max(0, i - K + 1)] through a[i], using a truncated window near the beginning.

Function headerSystemVerilog
function automatic void sliding_window_max_trailing(
  int k,
  ref int a[],
  ref int out[]
);

Example input and output

Use this case to check your interpretation
Input
a=[1,3,-1,-3,5,3,6,7]; K=3
Output
[1,3,3,3,5,5,6,7]
Explanation

Each output covers the current value and at most two predecessors; expired deque indices are removed before reporting the front.

02

Requirements (4)

  • Return one output per input index.
  • Evict indices that are no longer in the trailing window.
  • Maintain remaining candidates in decreasing-value order.
  • Run in O(n) time.