DescriptionQ724
Q724FWASIC interview problem
Group diagnostic tags without dynamic allocation
TechniquesFirmwareAnagramsFixed storage
DifficultyMedium
TopicStrings
LanguageSystemVerilog
Requirements4 checkpoints
01
Problem
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.
Type declarationSystemVerilog
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
);Example input and output
Use this case to check your interpretationInput
tags=["eat","tea","tan","ate"]Output
groups=[["eat","tea","ate"],["tan"]]Explanation
The letter-count key groups the three anagrams, while first-group and member encounter order remain unchanged.
02
Requirements (4)
- 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.
- Use the exact tag length plus 26 letter counts as the grouping key rather than relying on a hash alone.
- Order groups by the first member seen, preserve member order, and publish group_start[0]=0 and group_start[group_count]=count.
- Use only bounded workspace and leave all outputs byte-for-byte unchanged for every invalid argument or malformed tag.
