Sets, LRU Cache & a Thread-Safe Batch Writer
- Build an integer set on a resizable array and explain what resizing costs
- Move the same set into hash buckets with a load factor and a safe modulo
- Write a batch writer that flushes on size or time and calls the database outside the lock
- Build an LRU cache with constant-time get and put
Some Disney rounds skip the puzzle and hand you a data structure to build. Three of these turned up in 2026. A streaming software engineer phone screen in August asked for a set of integers without any built-in set or map, then spent its last 20 minutes on a writer that batches database inserts coming from many threads. A software engineer onsite in January asked for an LRU cache.
Your team will likely ask something different, so learn the shape behind all three. It's a familiar structure with the usual shortcut taken away, followed by questions about what each operation costs. That part you can prepare for.
One phone screen, two questions
The August 2026 candidate was told to write a set, and at first only Java was allowed. Built-in sets and maps were off the table, and so was writing a hash function. The question started from a plain resizable array, with duplicates to handle and a policy for growing and shrinking it, and then turned to how hashing values into indices would make it faster. Partway through, the candidate asked to switch to Python.
With about 20 minutes left, a second question arrived, about streaming batch processing. Records come in from a stream on many threads and have to land in a database. The candidate built a thread pool that wrote records in parallel. The interviewer pointed out that the database already had a batch insert API, and said the focus was "caching combined with multithreading". In other words, hold the records in a buffer and send them in batches. The screen ended in a rejection.
Both questions reward the same habit. Write the plain version that works, say what it costs, then fix the slow part. For the set, the slow part is scanning the array, and hashing removes it. For the writer it's one database call per record, and a buffer removes that.
A set on a resizable array
Without a hash table, a set is an array plus a rule about duplicates. Keep the values sorted and contains becomes a binary search. Adding and removing still shift elements, so each costs O(n). The resize is where the cost questions live. Double the array when it fills, and halve it only when it drops to a quarter full.
Integer Set on a Resizable Array
Problem
IntSet, a set of integers, without any built-in set or map type. Store the values in a fixed-size array that starts with 4 slots, and manage its size yourself.add(value) returns true if the value was new and false if it was already there. remove(value) returns true if the value was present. contains(value) says whether it's present, and size() returns how many values the set holds.When
add finds the array full, double it before inserting. After a remove, if the set holds a quarter of the slots or fewer, halve the array, but never below 4 slots. capacity() returns the current slot count and values() returns the values in ascending order.- IntSet()
- add(5)→ true
- add(1)→ true
- add(5)→ false
- contains(1)→ true
- contains(3)→ false
- size()→ 2
- values()→ [1,5]
The second add(5) finds 5 already there and returns false, so the set still holds two values.
Keep the values sorted at the front of the array and track a count. A binary search gives the index where a value is or would go, and add and remove shift everything after that index by one.
Integer Set on a Resizable Array
Click "Run" to execute your code
add still scans for a duplicate, but remove can move the last value into the gap instead of shifting everything after it. Every operation is then an O(n) scan, which is exactly the cost the hashed version in the next problem removes.Hashing values into buckets
The second half of the set question turned to hashing values into indices. For integers there's no separate hash function to write, because the value modulo the number of buckets is already an index. Each bucket holds the few values that land there, so contains scans a short list instead of the whole set. In the screen this step was only discussed. Code it once anyway, and the conversation gets much easier.
Integer Set With Hash Buckets
Problem
HashIntSet, again with no built-in set or map. Keep an array of 8 buckets, where each bucket is a small resizable array. A value belongs in bucket value mod bucketCount, using a modulo that never returns a negative index.add, remove, contains and size behave as in the array version. After an add, if the set holds more than three quarters as many values as there are buckets, double the bucket count and move every value to its new bucket. Removing never shrinks the table.buckets() returns the bucket count and values() returns every value in ascending order.- HashIntSet()
- add(1)→ true
- add(9)→ true
- contains(9)→ true
- contains(17)→ false
- add(9)→ false
- size()→ 2
- buckets()→ 8
1, 9 and 17 all map to bucket 1. contains(17) scans that one bucket and doesn't find it.
An array of buckets, each a small list. The bucket index is the value modulo the bucket count. Count the values, and when the count passes three quarters of the buckets, build a table twice the size and re-insert every value.
Integer Set With Hash Buckets
Click "Run" to execute your code
% gives a negative result for a negative value, so use Math.floorMod or add the bucket count back. Then say what the load factor buys. With at most three quarters as many values as buckets, the average bucket holds less than one value, so every operation is O(1) on average and O(n) when everything collides.remove harder, because an emptied slot in the middle of a run breaks later lookups. The usual fix is a tombstone marker that lookups step over and inserts reuse.A thread-safe batch writer
This was the last 20 minutes of the same August 2026 screen. A strong answer covers five things. Batches go out when enough records wait or when the oldest has waited too long. The lock stays out of the database call. A full buffer pushes back on producers, and shutdown drains what's left. Failed batches are retried without losing their order.
The class below has all of that, with the threads replaced by explicit calls and a clock you pass in, so the tests come out the same every run. The locks are real, and the walkthrough shows the Java version with an actual flusher thread.
Thread-Safe Buffered Batch Writer
Problem
BatchWriter(maxBatch, maxWait, maxPending). Producers on many threads call write(record, now), and records reach the database only through its batch insert. Times are integer milliseconds passed in by the caller.write buffers the record and returns true, then sends a batch if maxBatch records are waiting. If the writer is closed or maxPending records are already waiting, it returns false and buffers nothing. tick(now) sends a batch if the oldest waiting record arrived at least maxWait ms ago, and returns how many records it wrote.A batch is the oldest
maxBatch waiting records, tried up to 3 times. If all 3 attempts fail, the records go back to the front of the buffer in their original order. outage(calls) makes the database's next calls batch inserts fail, and outage(0) ends an outage.close(now) refuses new writes, then sends batches until the buffer is empty or a batch fails, and returns how many records it wrote. written() returns the batches the database accepted, in order.- BatchWriter(3, 100, 10)
- write("a", 0)→ true
- write("b", 1)→ true
- write("c", 2)→ true
- written()→ [["a","b","c"]]
The third write fills a batch, so it goes to the database right away.
Guard the buffer with one lock and hold it only to append or to cut a batch off the front. Call the database after releasing it. A second lock that only flushers take keeps one batch in flight at a time, which keeps the batches in order.
Thread-Safe Buffered Batch Writer
Click "Run" to execute your code
ArrayBlockingQueue and one flusher thread that fills each batch with a timed poll.false. A producer that has to keep every record can wait for room on a condition the flusher signals after each batch. Give that wait a timeout, so a dead database can't hang every producer forever. If records must survive a crash, retries aren't enough. Write them to a durable log first, or give each record an id the database deduplicates so a retried batch can't insert twice.LRU cache with constant-time get and put
A software engineer onsite in January 2026 asked for an LRU cache with constant-time get and put. It matches LeetCode 146, so the value here is a clean build you can write without stalling, plus the Java shortcut and when to use it.
LRU Cache
Problem
LRUCache(capacity) for integer keys and values. get(key) returns the value, or -1 if the key isn't cached, and counts as a use of that key.put(key, value) inserts the key or updates its value, and also counts as a use. If inserting a new key would go over capacity, first evict the key used least recently. Both calls must run in O(1) on average.- LRUCache(2)
- put(1, 1)
- put(2, 2)
- get(1)→ 1
- put(3, 3)
- get(2)→ -1
- get(3)→ 3
get(1) makes key 2 the least recently used, so put(3, 3) evicts 2.
A hash map from key to node, plus a doubly linked list of nodes from most to least recently used. Sentinel nodes at both ends remove the empty-list special cases.
LRU Cache
Click "Run" to execute your code
LinkedHashMap in access order with removeEldestEntry gives you an LRU cache in a few lines, then ask whether the interviewer wants it built by hand. The hand-built version is a hash map from key to node plus a doubly linked list, so moving a node to the front and evicting from the back never walks the list. Most bugs hide in updating a key that already exists. Change the value, move the node and evict nothing.get reorders the list, so even reads need the lock. One lock around both methods is correct and simple. Under heavy load, split the keys across several independent caches by key, each with its own lock, and accept that eviction becomes least recently used per shard.Common questions
Does Disney ask LRU cache in coding interviews?
It has come up. A software engineer onsite in January 2026 asked for an LRU cache with constant-time get and put, which is LeetCode 146. Prepare it as a classic any team can ask. Build the hand version in your interview language and know the library shortcut.
Does the Disney technical interview ask multithreading questions?
Sometimes. The August 2026 streaming phone screen ended with a thread-safe batch writer, where records from many threads go to the database through its batch API. The interviewer wanted buffering and batching rather than a pool of single writes. Know how a bounded queue, a lock held outside I/O and a flusher thread fit together.
Can I use Python in a Disney coding interview?
It depends on the team. The August 2026 set question required Java at first, and the candidate asked to switch to Python partway. Java leads recent Disney backend reports, so if the posting names Java, practise these problems in Java.
Are these Disney LeetCode questions?
Two have close LeetCode versions. The set is near 705, Design HashSet, though the Disney screen started from a resizable array and banned a hand-written hash function. LRU cache is 146. Nothing on LeetCode matches the batch writer, which is closer to everyday backend work than to a puzzle.
Key Takeaways
- ✓An August 2026 Disney screen asked for a set with no built-in hashing, then a thread-safe batch writer.
- ✓Double the array when full and halve it at a quarter, so resizing adds O(1) amortised per call.
- ✓In a batch writer, cut the batch under the lock and call the database only after releasing it.
- ✓For an LRU cache, pair a hash map with a doubly linked list, and treat every update as a use.
Disney interview guideKnow what Disney asks before you walk in.
27 coding · 6 system design · 16 behavioral questions
Get their questions first.
InterviewLegend is independent and not affiliated with or endorsed by any company it covers.