Vizient interview question

Just a medium leetcode question