Pregunta de entrevista de Google

Matrix question and something with loops