Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Count target-sum bursts

Hardware interview practice

Count target-sum bursts

MediumHardware AlgorithmsSystemVerilog

Count every nonempty contiguous range in a frame of signed occupancy changes whose sum equals a programmable target. Overlapping ranges and multiple matches ending at one sample all count.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Reviewed example

Work through one case

Input
signed deltas = [1, -1, 1, -1]; target=0
Expected output
matching contiguous ranges=4

Prefix values are [0,1,0,1,0]; equal-prefix pairs contribute three zero-prefix pairs and one one-prefix pair.

What to cover

Requirements

  1. Support 1 to 32 signed eight-bit deltas, a signed 13-bit target, and a 10-bit result up to 528.
  2. Insert the initial zero prefix before processing the first sample.
  3. Count every previous occurrence of current_prefix - target, including repeated equal prefixes.
  4. Sign-extend to 14 bits for the subtraction and comparison so the lookup key cannot wrap.
  5. Use fixed bounded storage and hold the final count stable under backpressure.
asic.fyi · Learn silicon end to end.info@asic.fyi