Veeva Systems interview question

Leetcode question that was medium difficulty