LinkedIn interview question

Matrix problem