Hardware interview practice
Measure the maximum gain in a sample stream
For each framed stream of unsigned samples, report the maximum nonnegative later-minus-earlier gain and its endpoints. Return zero and indices (0,0) when no positive gain exists.
Reviewed example
Work through one case
Input
accepted sample frame=[7,1,5,2,6]Expected output
max_gain=5; start_index=1; end_index=4The running minimum becomes value 1 at index 1, and later value 6 gives the largest strictly later gain.
What to cover
Requirements
- Support frames of one through MAX_SAMPLES accepted samples.
- Use strictly earlier and later endpoints for every positive result.
- Break gain ties by earliest start index and then earliest end index.
- Advance the sample index only on a handshake and hold all result fields stable under backpressure.
