Pregunta de entrevista de Intel Corporation

MEX question leetcode medium, follow up hard