Pergunta de entrevista da empresa Capital One

LeetCode level hard question for final round.