Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ927
Page ↗
Q927FWAppleASIC interview problem

Zero matrix rows and columns in place

TechniquesFirmware & ValidationFirmware / Validationzero matrix rows and columns in place
DifficultyMedium
TopicFirmware & Validation
LanguageC++
Requirements4 checkpoints
01

Problem

Firmware owns a row-major matrix. If an original element is zero, every element in that element's row and column must become zero. Write C++ code for the matrix transformation with constant auxiliary storage.

Starting declarationC++
enum MZStatus { MZ_OK, MZ_BAD_ARG };
MZStatus zero_rows_cols(int32_t *m,
size_t rows, size_t cols);

Example input and output

Use this case to check your interpretation
Input
Matrix [[1,2,0],[4,5,6]] with rows=2 and cols=3.
Output
Return MZ_OK; matrix becomes [[0,0,0],[4,5,0]].
Explanation

The original zero at row 0, column 2 marks exactly its entire row and its entire column for clearing.

02

Requirements (4)

  • Treat m as row-major. Decisions must be based only on zeros present when the function is called.
  • Use O(1) auxiliary storage beyond scalar variables; the matrix itself may hold row and column markers.
  • If rows=0 or cols=0, return MZ_OK without dereferencing m; otherwise m must be nonnull and rows*cols must fit size_t.
  • On a bad argument return MZ_BAD_ARG before writing; on success return MZ_OK after completing all required zeros.