Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Report the top-K opcode frequencies

Hardware interview practice

Report the top-K opcode frequencies

MediumStreaming AlgorithmsSystemVerilog

Count the opcode IDs in a completed packet frame and emit up to K distinct opcodes in descending frequency order, breaking equal counts by lower opcode ID.

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
accepted opcodes = [3, 1, 3, 2, 1, 3]; K=2
Expected output
ranked outputs = [(opcode=3,count=3), (opcode=1,count=2)]

Opcode 3 has the highest frequency and opcode 1 is the next distinct frequency winner.

What to cover

Requirements

  1. Support opcode IDs 0 to 15, frame lengths from 1 to 64, and K from 1 to 4 captured with the first item.
  2. Clear or invalidate all 16 histogram bins between frames.
  3. Do not select an opcode twice and never emit an absent opcode.
  4. If fewer than K distinct opcodes appear, emit only those present.
  5. Begin ranking only after the frame is complete and hold each output token stable while stalled.
asic.fyi · Learn silicon end to end.info@asic.fyi