Tavant Interview Question

DS problem. Frequency count, bracket balance.