Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Group diagnostic tags without dynamic allocation

Hardware interview practice

Group diagnostic tags without dynamic allocation

MediumStringsSystemVerilog

Group as many as 32 fixed-record lowercase diagnostic tags into anagram families without heap allocation, while preserving both first-group order and member input order.

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 →
Starting point

Question code

typedef struct { byte text[17]; } diag_tag_t;

function automatic bit group_tags(
  input diag_tag_t tags[32],
  input int unsigned count,
  ref byte unsigned order[32],
  ref byte unsigned group_start[33],
  ref int unsigned group_count
);
Reviewed example

Work through one case

Input
tags=["eat","tea","tan","ate"]
Expected output
groups=[["eat","tea","ate"],["tan"]]

The letter-count key groups the three anagrams, while first-group and member encounter order remain unchanged.

What to cover

Requirements

  1. Validate every active record before writing: a terminator must occur within 17 bytes, length must be 1 through 16, and all characters must be lowercase ASCII.
  2. Use the exact tag length plus 26 letter counts as the grouping key rather than relying on a hash alone.
  3. Order groups by the first member seen, preserve member order, and publish group_start[0]=0 and group_start[group_count]=count.
  4. Use only bounded workspace and leave all outputs byte-for-byte unchanged for every invalid argument or malformed tag.
asic.fyi · Learn silicon end to end.info@asic.fyi