DevPrep

All topics › Algorithms & data structures

Set and Dictionary complexity. Advantage over Array?

Junior PRO

The gist

Set is an unordered collection of unique elements; Dictionary holds key–value pairs with unique keys. Both are hash tables, hence:

A Set element and a Dictionary key must be Hashable; the dictionary value can be anything.

The rest of this answer, with code and interview follow-ups, is in the DevPrep app.

Read the full answer in DevPrep

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store