Pergunta de entrevista da empresa Robinhood

Typical leetcode question with two steps