Thomson Reuters interview question

Leetcode question, very basic, doable