Pregunta de entrevista de XYZ

Matrix and dp based question.