Sort characters by frequency | Amazon Interview Question