LinkedIn Interview Question

Matrix problem