Hardware interview practice
Minimize descriptor count for a payload
Express a target payload length as an exact sum of supported transfer-block sizes while using the fewest descriptors. Return one count per original size slot, or report that no decomposition exists.
Reviewed example
Work through one case
Input
target=18; block sizes in original slot order = [6, 4, 9]Expected output
reachable=1; descriptor_count=2; slot_counts=[0, 0, 2]Two 9-byte blocks are an exact decomposition and no one-descriptor block equals 18.
What to cover
Requirements
- Support target lengths from 0 to 64 and one to four unique positive block sizes supplied in any order.
- Treat target zero as a valid zero-descriptor result and represent unreachable totals explicitly.
- On equal descriptor counts, prefer more uses of the largest block size, then the next largest.
- Keep enough fixed-size metadata to return counts in the original input-slot order.
- Hold the response stable under backpressure.
