Hardware interview practice
Count connected fault regions in a tile map
Accept a row-major fault bitmap up to 8 by 8 pixels and report how many 4-connected components contain a one. Diagonal contact alone does not connect regions.
Reviewed example
Work through one case
Input
width=3,height=3; row-major fault bitmap rows=[110,010,001]Expected output
component_count=2The upper three set cells are four-connected; the bottom-right bit touches only diagonally and therefore forms a second component.
What to cover
Requirements
- Capture a width and height from 1 through 8, followed by exactly width x height pixels.
- Use fixed-size frame storage, a visited bitmap, and a bounded stack or queue; do not use recursion or dynamic allocation.
- Check row and column boundaries before enqueuing each of the four neighbors.
- Mark a cell visited when it enters the work list so it cannot be inserted more than once.
- Hold component_count and result_valid stable under backpressure and complete internal work within 2048 cycles.
