Pregunta de entrevista de Tableau Software

medium difficulty algorithm problem