Amazon Interview Question

String sorting using a nested dictionary