Pregunta de entrevista de Thomson Reuters

Leetcode question, very basic, doable