Pregunta de entrevista de MathWorks

Leetcode question, two technical interview with a total about 4.