Replace HashMap with array to speed up the program 2x, and it can pass the small data set now, but still fails for large data set.