Hardware interview practice
Optimize nonadjacent bank activation
Choose a maximum-benefit subset of static random-access memory (SRAM) banks when adjacent banks may not be active in the same maintenance interval. Return the total score and exact selection mask.
Reviewed example
Work through one case
Input
benefit by bank = [5, 1, 4, 9, 2]Expected output
score=14; selected_mask=5'b01001; selected_count=2Banks 0 and 3 are nonadjacent and total 14, which exceeds every other legal subset.
What to cover
Requirements
- Accept a frame of 1 to 16 unsigned eight-bit benefits; the first and last banks are not adjacent.
- Select no adjacent pair and maximize the total benefit.
- On a score tie, prefer fewer selected banks; if still tied, prefer the mask that selects the first differing lower-index bank.
- Clear mask bits above the frame length and return the selected-bank popcount.
- Hold the final score, mask, and count stable while stalled.
