Pregunta de entrevista de Tavant

DS problem. Frequency count, bracket balance.