Pregunta de entrevista de Generac

Leetcode question that was medium