Review: Hashmap Problems Posted on January 31, 2018July 26, 2020 by braindenny Review Hashmap code problems Top 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() Contains Duplicate II Leetcode: Contains Duplicate II 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 CheatSheet: Common Code Problems & Follow-ups 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 DictionaryLeetCode: Unique Word AbbreviationLeetCode: Unique Number of OccurrencesLeetCode: Unique Morse Code WordsLeetCode: Unique Email AddressesLeetCode: Uncommon Words from Two SentencesLeetCode: Two Sum IV – Input is a BSTLeetCode: Triples with Bitwise AND Equal To ZeroLeetCode: Sum of Distances in TreeLeetCode: Subdomain Visit CountLeetCode: Subarray Sum Equals KLeetCode: Split Array with Equal SumLeetCode: Smallest Integer Divisible by KLeetCode: Simplified FractionsLeetCode: Shortest Word Distance IILeetCode: Shortest Completing WordLeetCode: Sentence SimilarityLeetCode: Reduce Array Size to The HalfLeetCode: People Whose List of Favorite Companies Is Not a Subset of Another ListLeetCode: Pairs of Songs With Total Durations Divisible by 60LeetCode: Number of Distinct IslandsLeetCode: Number of BoomerangsLeetCode: Number of AtomsLeetCode: Minimum Number of Frogs CroakingLeetCode: Minimum Area Rectangle IILeetCode: Maximum Number of BalloonsLeetCode: Make Two Arrays Equal by Reversing Sub-arraysLeetCode: Longest String ChainLeetCode: Longest Repeating SubstringLeetCode: Longest Harmonious SubsequenceLeetCode: Longest Duplicate SubstringLeetCode: Line ReflectionLeetCode: Largest Component Size by Common FactorLeetCode: Kill ProcessLeetCode: K-diff Pairs in an ArrayLeetCode: Jump Game IVLeetCode: Jewels and StonesLeetCode: Intersection of Two ArraysLeetCode: Increasing SubsequencesLeetCode: H-IndexLeetCode: Group Shifted StringsLeetCode: Group AnagramsLeetCode: Graph Valid TreeLeetCode: Friends Of Appropriate AgesLeetCode: Fraction to Recurring DecimalLeetCode: First Unique NumberLeetCode: Find Words That Can Be Formed by CharactersLeetCode: Find Smallest Common Element in All RowsLeetCode: Find Duplicate SubtreesLeetCode: Find Duplicate File in SystemLeetCode: Find and Replace PatternLeetCode: Fair Candy SwapLeetCode: Distinct Echo SubstringsLeetCode: Diagonal Traverse IILeetCode: Destination CityLeetCode: Design Underground SystemLeetCode: Design Excel Sum FormulaLeetCode: Counting ElementsLeetCode: Count Vowels PermutationLeetCode: Count Number of Nice SubarraysLeetCode: Contains Duplicate IILeetCode: Contains DuplicateLeetCode: Confusing NumberLeetCode: Check If N and Its Double ExistLeetCode: Check If a String Contains All Binary Codes of Size KLeetCode: Brick WallLeetCode: Array of Doubled PairsLeetCode: 4Sum II See more blog posts. Post Views: 11