Pregunta de entrevista de BlackRock

Leetcode question at medium level