Google interview question

Hash map, sorting and time optimization