a O(n^2) time solution, TLE
solved by unordered_map, O(n) time and O(n) space