Skip to content

Prepare For Coder Interview – Denny

  • Basic
  • Medium
  • Hard
  • Architect
  • Life

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 Problems
  • LintCode: Word Frequency Count
  • LintCode: Valid Array
  • LintCode: Same Number
  • LintCode: Longest AB Substring
  • LintCode: Function Runtime
  • LintCode: Fermat Point Of Graphs
  • Leetcode: X of a Kind in a Deck of Cards
  • Leetcode: Vowel Spellchecker
  • Leetcode: Verifying an Alien Dictionary

See more blogposts.

linkedin
github
slack

Post Views: 11
Posted in ReviewTagged hashmap, review

Post navigation

Leetcode: All O`one Data Structure
Review: Rotate Problems

Leave a Reply Cancel reply

Your email address will not be published.

Tags

#array #backtracking #bfs #binarytree #bitmanipulation #classic #codetemplate #combination #dfs #dynamicprogramming #game #graph #greedy #heap #inspiring #interval #linkedlist #manydetails #math #misc #palindrome #recursive #slidingwindow #stack #string #subarray #trie #twopointer #twosum baseconversion binarysearch editdistance hashmap knapsack monotone oodesign presum redo review rotatelist series sql topologicalsort treetraversal unionfind

Recent Posts

  • Leetcode: Palindrome Partitioning III
  • Leetcode: Biggest Single Number
  • Leetcode: Max Consecutive Ones II
  • Leetcode: Minimum Cost to Connect Sticks
  • Leetcode: Minimum Swaps to Group All 1’s Together

Recent Comments

    Archives

    Categories

    • Amusing
    • Basic
    • Easy
    • Hard
    • Life
    • Medium
    • Resource
    • Review
    • Series
    • Uncategorized
    Proudly powered by WordPress | Theme: petals by Aurorum.