Amazon interview question

String sorting using a nested dictionary