Review: Hashmap Problems Posted on January 31, 2018November 14, 2019 by braindenny Review Hashmap code problems Questions Name Example Use a local hashmap, instead of a global one Leetcode: Increasing Subsequences One hashmap vs two hashmap Leetcode: Before and After Puzzle Hashmap may make code more complicated Leetcode: Find K-th Smallest Pair Distance Mapping data range of getRand algorithm Leetcode: Implement Rand10() Using Rand7() Rolling hash Use a tuple as key Group Shifted Strings ## Blog link: https://code.dennyzhang.com/group-shifted-strings class Solution: def groupStrings(self, strings): """ :type strings: List[str] :rtype: List[List[str]] """ import collections m = collections.defaultdict(list) for s in strings: # ba -> (0, 25) # az -> (0, 25) tup = tuple([(ord(ch)-ord(s[0]))%26 for ch in s]) m[tup].append(s) return [m[key] for key in m] CheatSheet: Leetcode For Code Interview See all hashmap problems: #hashmap Review: Hashmap ProblemsLintCode: Word Frequency CountLintCode: Valid ArrayLintCode: Same NumberLintCode: Longest AB SubstringLintCode: Function RuntimeLintCode: Fermat Point Of GraphsLeetcode: X of a Kind in a Deck of CardsLeetcode: Vowel SpellcheckerLeetcode: Verifying an Alien Dictionary See more blogposts. Post Views: 11