Hardware interview practice
Intersect redundant-core fault lists
Return the multiset intersection of two bounded fault-ID lists, preserving the first list's encounter order and consuming each match only once.
Starting point
Question code
typedef enum { IX_OK, IX_EINVAL, IX_ENOSPC } ix_rc_t;
ix_rc_t fault_intersection(const uint16_t *a, size_t na,
const uint16_t *b, size_t nb,
uint16_t *out, size_t cap,
size_t *nout);
// na and nb are at most 32.Reviewed example
Work through one case
Input
A=[5,2,5,7]; B=[5,5,8]Expected output
intersection=[5,5]Both copies of 5 are consumed once in A encounter order; 2 and 7 have no available match.
What to cover
Requirements
- Emit each identifier min(count_a, count_b) times in A's encounter order.
- Use fixed state for at most 32 entries and do not modify either input.
- Count the complete result before writing and return no-space without exposing a partial output.
- Validate pointers, lengths, arithmetic, and output/input overlap while preserving all outputs on error.
