Thomson Reuters Interview Question

Leetcode question, very basic, doable