Implement a simplified LEFT JOIN for 2 Hashmaps
- Write a function that LEFT JOINs two hashmaps into a single data structure.
- The first parameter is a hashmap that has word strings as keys, and a synonym of the key as values.
- The second parameter is a hashmap that has word strings as keys, and antonyms of the key as values.
- Combine the key and corresponding values (if they exist) into a new data structure according to LEFT JOIN logic.
LEFT JOIN means all the values in the first hashmap are returned, and if values exist in the “right” hashmap, they are appended to the result row. If no values exist in the right hashmap, then some flavor of
NULL
should be appended to the result row. - The returned data structure that holds the results is up to you. It doesn’t need to exactly match the output below, so long as it achieves the LEFT JOIN logic.
- Avoid utilizing any of the library methods available to your language.
To approach this challenge, I created a method that takes in a synonym and antonym hashtable. The method then goes through the synonym hashtable looking for keys. When a key is found, the word and its synonym are added to a string. The method then checks if the key exists in the antonym hashtable. If it does, the antonym is appended to the string. This string is then added to a list. When the end of the hashtable is reached, the list is returned by the method.
Time: O(n) Space: O(n)