Pregunta de entrevista de Pinterest

some algorithm question using matrix