Implemented another version using LinkedHashMap, but still does not pass the time constraint