Hardware interview practice
Debug a signed sliding-window peak
Write an independent exact-sum oracle for a fixed-window peak detector that fails on some all-negative traces, plus a rolling-update helper that can be cross-checked against it.
Reviewed example
Work through one case
Input
signed samples=[-8,-3,-5]; window_len=2Expected output
best_sum=-8; best_start=1Legal window sums are -11 and -8; initializing best to zero would incorrectly report a nonexistent nonnegative window.
What to cover
Requirements
- Sign-extend every 12-bit sample before addition and initialize the legal best from the first window rather than zero.
- Use independent O(n x k) recomputation as the trusted oracle; a rolling sum may be cross-checked but must not replace it.
- Compare integer sums instead of real-number averages because every candidate has the same denominator.
- Return request_error with result_valid=0 when window_len is zero, exceeds sample_count, or sample_count exceeds 32.
- Choose the lowest start for equal sums and explain tests for signed extrema, all-negative data, tied maxima, window boundaries, and each invalid class.
