DMA Stream Distribution
Reported by candidates from Etched's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that breaks a naive solution in Etched's DMA Stream Distribution is the moment a stream ends exactly where a region ends. Reported in September 2026, this one looks like a simple fill problem and then bites you on boundaries. It's a two-pointer walk over streams and regions, tracking what's left in each. If you blank on the pointer advances during the live OA, StealthCoder is the invisible safety net that reads the problem and hands you a working solution. Know the shape before you sit down, though. It's short once you see it.
The problem
A DMA controller receives ordered write streams and fills ordered memory regions. Stream i contains streamBytes[i] bytes, and region j has regionCapacities[j] available bytes. Consume each stream fully before moving to the next stream, and fill each region before moving to the next region. A stream may span regions and a region may contain bytes from several streams. Return one row [streamIndex, regionIndex, bytesMoved] for every non-empty transfer. Total region capacity is sufficient for all streams. Function distributeDmaStreams(streamBytes: int[], regionCapacities: int[]) → int[][] Examples Example 1 streamBytes = [8,4] regionCapacities = [5,5,2] return = [[0,0,5],[0,1,3],[1,1,2],[1,2,2]] The first stream fills region 0 and uses three bytes of region 1; the second finishes region 1 and fills region 2. Example 2 streamBytes = [3,2] regionCapacities = [10] return = [[0,0,3],[1,0,2]] Both streams fit sequentially in the same region. Constraints 0 <= streamBytes.length, regionCapacities.length <= 100000 Every byte count and capacity is positive. Total region capacity is at least total stream bytes.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a single pass with two pointers and two remainders. Keep i for the current stream with its remaining bytes, and j for the current region with its remaining capacity. Each step moves min(remainingStream, remainingRegion), appends [i, j, moved] only if moved is positive, subtracts it from both, then advances whichever hit zero. If both hit zero, advance both. That's the boundary case people miss. Advance only one and you emit an empty transfer next round, or reuse a full region. Don't copy bytes one at a time. With up to 100000 on each side, you want O(n + m), not O(total bytes). Empty inputs just return an empty list. Capacity is guaranteed sufficient, so j never runs off the end. If you freeze on the loop conditions in the live OA, StealthCoder gives you the clean version as a hedge.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill DMA Stream Distribution cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Etched's OA.
Etched reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
DMA Stream Distribution FAQ
What's the trick in DMA Stream Distribution?+
Two pointers with remaining counts. Each iteration moves the minimum of the stream's remaining bytes and the region's remaining capacity, records it, subtracts, then advances whichever side reached zero. It runs in linear time over streams plus regions, and never touches individual bytes.
What edge case breaks the naive solution?+
A stream ending exactly when a region fills. If you advance only one pointer, the next iteration moves zero bytes and emits a bogus row. Advance both when both hit zero, and only append rows where bytesMoved is positive.
How hard is this really?+
Easy to medium. There's no fancy data structure, just careful bookkeeping. Most failures come from off-by-one pointer advances or from looping per byte, which is too slow when counts reach 100000 entries with large values.
Do I need to handle empty inputs?+
Yes. Either array can have length zero. If there are no streams, return an empty list. Since total capacity covers total bytes, empty regions only occur with empty streams, so a loop bounded by the stream pointer handles it naturally.
How do I prepare in 48 hours for this kind of OA?+
Write this one from scratch twice, then do a few merge-intervals and two-pointer simulation problems. Focus on tracking remainders and advancing pointers cleanly. Test with exact-boundary cases, single-element arrays, and one stream spanning many regions.