Problem: 242. Valid Anagram
Time: 10min
Method: hashtable - list
Reflection: To be a valid anagram, each letter can only be used once, so need a hashtable to count the letters. Set() does not work.
Time complexity: O(N)
Space complexity: O(1)
Problem: 349. Intersection of Two Arrays
Time: 2min
Method: hashtable - set
Reflection: set() returns unordered unique elements. Set is easy to implement, but more cost of space and time.
Time complexity: O(N+M)
Space complexity: O(N)
Problem: 202. Happy Number
Time:
Method: hashtable - list
Reflection: Hashtable is used to detect cycle. divmod() to get both divident and mode. After each loop, reset n = ssq.
Time complexity: O(logN)
Space complexity: O(logN)
Problem: 1. Two Sum
Time: 5min
Method: hashtable - dict
Reflection: Quesiton prompt mentions exactly one solution. So can use hashtable to find the target pair by selecting from previously iterated elements in linear time.
Time complexity: O(N)
Space complexity: O(N)