Changed list to dictionary to avoid O(n) time, and get O(1)