XYZ Interview Question

Matrix and dp based question.