All questions
Showing of 75What is an array and how is it stored in memory?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
An array is a fixed sequence of elements of the same type, laid out back to back in one contiguous block of memory. Because every element takes the same number of bytes, the array only needs to remember its starting address and its length.
That layout is why arrays feel so simple. The values sit next to each other in order, with no gaps and no pointers linking them. A five-element integer array is just five integers packed tightly, one after another.
The packing has real consequences. Reading nearby elements is fast, since the CPU pulls in whole cache lines at once. The cost is rigidity: the block is one piece, so you cannot cheaply grow it in place when neighboring memory is already taken.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between a static array and a dynamic array?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A static array has a fixed size chosen when it is created, and that size never changes. A dynamic array can grow and shrink at runtime, resizing itself as you add or remove elements.
Under the hood, a dynamic array still uses a contiguous block. When that block fills up, it allocates a larger one and copies the elements across. You get flexibility, but occasional resize work happens behind the scenes.
Use a static array when you know the count ahead of time and want zero overhead. Reach for a dynamic array, like a Python list or a Java ArrayList, when the size is unknown or keeps changing. Access stays O(1) for both; only the growth behavior differs between them.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How does a dynamic array grow, and why is append amortized O(1)?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Doubling storage on overflow is how a dynamic array stays fast. When the underlying block fills up, the array allocates a new block, usually twice as large, copies every element over, and releases the old one.
That copy costs O(n), so a single resize is not cheap. The saving grace is that resizes get rarer as the array grows. Going from 8 to 16 to 32 slots means the gaps between resizes keep doubling.
Spread the total copy work across every append, and each one averages out to constant time. That is what amortized O(1) means: individual appends occasionally spike, but the long-run cost per append stays flat. Appending a million items in a row stays fast overall.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Why is accessing an array element by its index O(1)?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Indexing is a single arithmetic step, not a search. Because an array is a contiguous block of equal-size elements, the computer locates any element with one formula.
address = base_address + index * element_size
Give it the index and it computes the exact memory location directly. No scanning, no walking through earlier elements first. Element 0 and element 999 take exactly the same amount of work to reach.
This constant-time access is the array's headline feature. It holds no matter how large the array grows, which is why arrays back so many other structures. The one requirement is that every element be the same size, so the multiplication always lands on the right spot.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Why does inserting into the middle of an array cost O(n)?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Inserting in the middle forces every later element to move. An array keeps its values packed with no gaps, so making room at position k means shifting everything from k onward one slot to the right.
If you insert near the front of a million-element array, you shift almost a million elements. That shifting is the O(n) cost, and it grows with how much sits after the insertion point.
Appending at the end avoids this, because nothing follows the last element. The same logic applies to deleting from the middle: the gap must be closed by shifting later elements left. When you need frequent middle inserts, an array is often the wrong tool.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is a hash table and what problem does it solve?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A hash table maps keys directly to values, so you can find things without scanning. It solves the problem of slow lookups in a plain array, where finding a value by content means checking elements one by one.
The idea is to compute a key's storage slot from the key itself. A hash function turns the key into a bucket number, and the value lives in that bucket. Later you recompute the same number and jump straight there.
This turns lookup, insert, and delete into roughly constant-time operations instead of O(n) scans. Phone books, caches, database indexes, and language dictionaries all lean on it. When you need fast membership tests or key-to-value access, a hash table is usually the answer.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Why are hash table lookups considered O(1) on average?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
On average, a good hash function scatters keys evenly across all the buckets. That even spread means most buckets hold very few entries, so finding the right one takes a small, roughly constant number of steps.
Look up a key and the table computes its bucket in one shot, then checks the handful of entries there. With a low load factor, that handful is close to one. There is no dependence on the total number of stored items.
The word average matters. If many keys collide into the same bucket, that bucket becomes a long chain and lookup slows down. Good hash functions and controlled load factors keep collisions rare, which is what keeps the everyday cost at O(1).
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between a hash set and a hash map?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A hash set stores only keys, while a hash map stores keys paired with values. Both use the same hashing machinery to place and find entries fast; the difference is what each slot actually holds.
A set answers one question: is this item present? You add values and later ask whether something is in the collection. A map answers a richer question: what value is associated with this key?
seen.add("alice"); // set: membership only
ages.set("alice", 30); // map: key -> value
Reach for a set when you only care about presence or uniqueness, like tracking which items you have already processed. Reach for a map when each key needs an attached value. Under the hood, a set is often just a map with dummy values.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is a hash collision and why do collisions happen?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Two different keys landing in the same bucket is a hash collision. It happens because a hash function squeezes a huge space of possible keys into a small, finite number of buckets.
There are far more possible keys than slots, so by pigeonhole some keys must share a slot. Even a great hash function cannot avoid this; it can only make collisions rare and evenly spread. Poor functions make it worse by clustering keys together.
Collisions are normal, not a bug, so every hash table has a plan for them. Common approaches store the clashing entries in a small list per bucket, or probe for the next open slot. Handling them well is what keeps lookups near O(1) instead of degrading.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is a string, and why are strings immutable in many languages?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A string is an ordered sequence of characters, usually stored as bytes that encode text. In many languages it behaves like a read-only array of characters that you can index and iterate over.
Immutability means that once a string is created, its contents never change. Operations that look like edits, such as replacing a character, actually build a brand new string and leave the original untouched.
Languages make this choice for safety and speed. Immutable strings can be shared freely between threads with no locking, and their hash code can be computed once and reused. The tradeoff is that heavy in-place editing wastes work creating copies. That is why building text in a loop should use a dedicated builder instead.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the load factor of a hash table?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The load factor is the ratio between the number of stored entries and the number of buckets. A table with 6 entries across 8 buckets sits at 0.75. It is a single number describing how crowded the table is.
Why care? As the load factor rises, more keys share buckets, so collisions and chain lengths grow. Lookups that were near constant start scanning longer chains. Implementations watch this number and resize once it crosses a set threshold.
A low load factor wastes memory on empty buckets. A high one wastes time on collisions. The whole point is to keep it in a healthy middle band so average operations stay near O(1).
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you insert, look up, and delete entries in a hash map?
What is a hash function and how does it map keys to buckets?
Why does checking whether an array contains a value cost O(n)?
Why is building a string by repeated concatenation in a loop slow?
How does chaining resolve collisions in a hash table?
When you loop over a hash map, is the iteration order predictable?
Why does appending to a string create a whole new string?
When should you choose an array over a linked list, and why?
What is the difference between a dynamic array's length and its capacity?
How does the growth factor of a dynamic array trade memory for copy work?
Why do arrays get better cache performance than node-based structures?
Why does a dynamic array rarely shrink its capacity when elements are removed?
Why use a string builder instead of repeated string concatenation?
Why can two strings of the same visible length have different byte lengths?
How can a substring share memory with its parent string, and what is the risk?
How is a two-dimensional array laid out in memory, and how does that affect traversal?
What is the cheapest way to delete from an array when order does not matter?
Why is comparing two strings for equality not always O(1)?
What is the difference between separate chaining and open addressing?
How does linear probing find and place an element?
What is primary clustering, and which collision scheme suffers from it?
When does a hash table decide to resize, and what triggers it?
Why is a resize still O(1) amortized despite copying every element?
What properties separate a good hash function from a bad one?
How does a map tell apart two keys that land in the same bucket?
What goes wrong when you mutate a key after putting it in a map?
What is the hashCode and equals contract, and why does it matter?
Under what conditions do hash table operations degrade to O(n)?
How do you choose a load factor threshold, and why around 0.75?
How does memory overhead compare between chaining and open addressing?
How does a hash set remove duplicate values in roughly O(n)?
When would you pick a tree-based ordered map over a hash map?
What is string interning, and when does it help or hurt?
Why is a string's hash code often cached after it is first computed?
How would you design a growable array that guarantees amortized O(1) appends?
What starts to break in a dynamic array as it nears a billion elements?
Why does an array of objects often scan slower than an array of values?
How does memory fragmentation affect allocating one large contiguous array?
What is small-string optimization, and what tradeoff does it make?
When is a rope better than a contiguous string for large editable text?
How do you shrink a dynamic array without causing repeated resize thrashing?
How can concurrent writes to adjacent array elements cause false sharing?
What does it take to make a dynamic array safe for concurrent access?
What are the benefits and hazards of copy-on-write arrays and strings?
How would you design a hash map from scratch, and what are the key decisions?
What problem does Robin Hood hashing solve, and how does it work?
How does cuckoo hashing guarantee worst-case O(1) lookups?
Why does deleting from an open-addressed table need tombstones?
Why is consistent hashing used to distribute keys across servers?
How can attacker-chosen keys force worst-case behavior, and how do you defend against it?
How does incremental resizing avoid a latency spike during rehash?
How do you make a hash map both safe and fast under heavy concurrency?
Can you resize a hash table without rehashing every existing key?
When is a minimal perfect hash worth building for a static key set?
When does a Bloom filter beat a hash set, and what do you give up?
How do you count distinct items at scale without storing every key?
When does hashing a long key dominate cost, and why cache its hash?
Should a hash table's bucket count be a power of two or a prime, and why?
How do probe length and memory trade off at very high load factors?
Why can open addressing beat chaining on modern cache hierarchies?
Why do hash maps iterate in an unstable order, and what makes iteration fail-fast?
How does a linked hash map preserve insertion order, and at what cost?
How likely are 64-bit hash collisions, and what does the birthday bound say?
How do you rebalance a sharded hash table when a node joins or leaves?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Arrays, Strings & Hash Tables cheatsheet
- 30-second mental model01
- Big-O quick reference02
- Arrays03
- Strings04
- Hash tables (Map / Set / dict)05
- Key & collision facts06
- Common pitfalls07
- Pick the structure08
- + 2 more inside
64 of 75 Arrays, Strings & Hash Tables answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.