Hardware interview practice
Group diagnostic tags without dynamic allocation
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.
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
- 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.
