Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Intersect redundant-core fault lists

Hardware interview practice

Intersect redundant-core fault lists

EasyFirmware AlgorithmsSystemVerilog

Return the multiset intersection of two bounded fault-ID lists, preserving the first list's encounter order and consuming each match only once.

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 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

  1. Emit each identifier min(count_a, count_b) times in A's encounter order.
  2. Use fixed state for at most 32 entries and do not modify either input.
  3. Count the complete result before writing and return no-space without exposing a partial output.
  4. Validate pointers, lengths, arithmetic, and output/input overlap while preserving all outputs on error.
Continue practicing

Related questions

Hardware-Software IntegrationVerify an in-place DMA merge transaction→Hardware-Software IntegrationVerify a DMA flood-fill transaction→
asic.fyi · Learn silicon end to end.info@asic.fyi