Amazon interview question

Hash map and some optimizations