LearnThatStack Ace your next interview
Computer Science Fundamentals
Arrays, Strings & Hash Tables.
Change topic Change
Practice · Questions

All questions

Showing of 75
Beginner 18
01

What is an array and how is it stored in memory?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

What is the difference between a static array and a dynamic array?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

How does a dynamic array grow, and why is append amortized O(1)?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

Why is accessing an array element by its index O(1)?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

Why does inserting into the middle of an array cost O(n)?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What is a hash table and what problem does it solve?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

Why are hash table lookups considered O(1) on average?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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).

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

What is the difference between a hash set and a hash map?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

09

What is a hash collision and why do collisions happen?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

10

What is a string, and why are strings immutable in many languages?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

11

What is the load factor of a hash table?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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).

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

12

How do you insert, look up, and delete entries in a hash map?

Part of Pro
13

What is a hash function and how does it map keys to buckets?

Part of Pro
14

Why does checking whether an array contains a value cost O(n)?

Part of Pro
15

Why is building a string by repeated concatenation in a loop slow?

Part of Pro
16

How does chaining resolve collisions in a hash table?

Part of Pro
17

When you loop over a hash map, is the iteration order predictable?

Part of Pro
18

Why does appending to a string create a whole new string?

Part of Pro
Intermediate 27
19

When should you choose an array over a linked list, and why?

Part of Pro
20

What is the difference between a dynamic array's length and its capacity?

Part of Pro
21

How does the growth factor of a dynamic array trade memory for copy work?

Part of Pro
22

Why do arrays get better cache performance than node-based structures?

Part of Pro
23

Why does a dynamic array rarely shrink its capacity when elements are removed?

Part of Pro
24

Why use a string builder instead of repeated string concatenation?

Part of Pro
25

Why can two strings of the same visible length have different byte lengths?

Part of Pro
26

How can a substring share memory with its parent string, and what is the risk?

Part of Pro
27

How is a two-dimensional array laid out in memory, and how does that affect traversal?

Part of Pro
28

What is the cheapest way to delete from an array when order does not matter?

Part of Pro
29

Why is comparing two strings for equality not always O(1)?

Part of Pro
30

What is the difference between separate chaining and open addressing?

Part of Pro
31

How does linear probing find and place an element?

Part of Pro
32

What is primary clustering, and which collision scheme suffers from it?

Part of Pro
33

When does a hash table decide to resize, and what triggers it?

Part of Pro
34

Why is a resize still O(1) amortized despite copying every element?

Part of Pro
35

What properties separate a good hash function from a bad one?

Part of Pro
36

How does a map tell apart two keys that land in the same bucket?

Part of Pro
37

What goes wrong when you mutate a key after putting it in a map?

Part of Pro
38

What is the hashCode and equals contract, and why does it matter?

Part of Pro
39

Under what conditions do hash table operations degrade to O(n)?

Part of Pro
40

How do you choose a load factor threshold, and why around 0.75?

Part of Pro
41

How does memory overhead compare between chaining and open addressing?

Part of Pro
42

How does a hash set remove duplicate values in roughly O(n)?

Part of Pro
43

When would you pick a tree-based ordered map over a hash map?

Part of Pro
44

What is string interning, and when does it help or hurt?

Part of Pro
45

Why is a string's hash code often cached after it is first computed?

Part of Pro
Expert 30
46

How would you design a growable array that guarantees amortized O(1) appends?

Part of Pro
47

What starts to break in a dynamic array as it nears a billion elements?

Part of Pro
48

Why does an array of objects often scan slower than an array of values?

Part of Pro
49

How does memory fragmentation affect allocating one large contiguous array?

Part of Pro
50

What is small-string optimization, and what tradeoff does it make?

Part of Pro
51

When is a rope better than a contiguous string for large editable text?

Part of Pro
52

How do you shrink a dynamic array without causing repeated resize thrashing?

Part of Pro
53

How can concurrent writes to adjacent array elements cause false sharing?

Part of Pro
54

What does it take to make a dynamic array safe for concurrent access?

Part of Pro
55

What are the benefits and hazards of copy-on-write arrays and strings?

Part of Pro
56

How would you design a hash map from scratch, and what are the key decisions?

Part of Pro
57

What problem does Robin Hood hashing solve, and how does it work?

Part of Pro
58

How does cuckoo hashing guarantee worst-case O(1) lookups?

Part of Pro
59

Why does deleting from an open-addressed table need tombstones?

Part of Pro
60

Why is consistent hashing used to distribute keys across servers?

Part of Pro
61

How can attacker-chosen keys force worst-case behavior, and how do you defend against it?

Part of Pro
62

How does incremental resizing avoid a latency spike during rehash?

Part of Pro
63

How do you make a hash map both safe and fast under heavy concurrency?

Part of Pro
64

Can you resize a hash table without rehashing every existing key?

Part of Pro
65

When is a minimal perfect hash worth building for a static key set?

Part of Pro
66

When does a Bloom filter beat a hash set, and what do you give up?

Part of Pro
67

How do you count distinct items at scale without storing every key?

Part of Pro
68

When does hashing a long key dominate cost, and why cache its hash?

Part of Pro
69

Should a hash table's bucket count be a power of two or a prime, and why?

Part of Pro
70

How do probe length and memory trade off at very high load factors?

Part of Pro
71

Why can open addressing beat chaining on modern cache hierarchies?

Part of Pro
72

Why do hash maps iterate in an unstable order, and what makes iteration fail-fast?

Part of Pro
73

How does a linked hash map preserve insertion order, and at what cost?

Part of Pro
74

How likely are 64-bit hash collisions, and what does the birthday bound say?

Part of Pro
75

How do you rebalance a sharded hash table when a node joins or leaves?

Part of Pro

No matches

Try a different filter or search term.

Know someone prepping for Arrays, Strings & Hash Tables? Send them this set.
Pro · $10/mo

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.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git