Pergunta de entrevista da empresa HeyGen

Standard leetcode question, probably medium difficulty