# use defaultdict to ensure default value of 0 is returned when accessing a key not exist in hash map # this effectively sets default frequency of all elements to 0 left_map = defaultdict (int) ...