Pregunta de entrevista de Rakuten

Leet code medium problem was asked