Data Structures That Appear in 80% of Tech Interviews
Knowing when to use which data structure is half the battle in coding interviews. The right choice can turn an O(n²) solution into O(n), or make an impossible problem trivial. This guide covers the essential data structures, their operations, complexities, and when to reach for each one.
Data Structure Frequency
Based on interview data from top tech companies:
1. Arrays
The most fundamental data structure. Arrays store elements in contiguous memory, enabling O(1) random access by index.
When to Use Arrays
You need fast access by index
The size is fixed or grows only at the end
You're iterating through elements sequentially
Memory efficiency matters (no pointer overhead)
2. Hash Maps (Dictionaries)
Hash maps provide O(1) average-case lookup, insert, and delete. They're the secret weapon for optimizing brute force solutions.
When to Use Hash Maps
You need fast lookups by key
Counting frequencies of elements
Checking for duplicates
Caching/memoization
Two Sum and its variations
Hash Sets
When you only need to track presence (not key-value pairs), use a set. Same O(1) operations as hash maps.
3. Stacks
Last-In-First-Out (LIFO). Think of a stack of plates - you can only add or remove from the top.
First-In-First-Out (FIFO). Like a line at a store - first person in line is first to be served.
When to Use Queues
BFS (level-order traversal)
Processing in order of arrival
Sliding window maximum (with deque)
Task scheduling
5. Linked Lists
Nodes connected by pointers. Unlike arrays, elements aren't contiguous in memory, enabling O(1) insertions and deletions once you have a reference to the node.
When to Use Linked Lists
Frequent insertions/deletions at arbitrary positions
Unknown size that grows/shrinks frequently
Implementing other data structures (stacks, queues, LRU cache)
A complete binary tree where each parent is smaller (min-heap) or larger (max-heap) than its children. Provides O(log n) insert and O(1) access to min/max.