Tableau Software interview question

medium difficulty algorithm problem