Hashing

Python Hashing Interview Questions

Hashing means using a dictionary or a set to look something up instantly, instead of searching the same list over and over. It is the standard answer when an interviewer asks you to make a working solution faster.

What hashing questions ask you to do

Across the questions here, these are the shapes that come up:

  • Find two values that add up to a target
  • Find the first repeated item, or the first unique one
  • Group items by something you work out from them
  • Count how often each value appears
  • Check membership against a large collection inside a loop

Common mistakes with hashing

A list is not a set. Checking whether something is in a list searches the whole list every single time, so moving that check inside a loop leaves you with exactly the slow solution you started with, wearing nicer syntax.

Questions to practice

Roles this comes up in

Companies these come from

Other topics