FastPrepBuild a Hash Table
Problems/Build a Hash Table

Build a Hash Table

Zillow logoZillow● MediumFULLTIMEINTERNOAPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Asked at Zillow in 2013 and 2023. A candidate for a senior iOS engineer job had to build their own dictionary, a hash table, in Swift in one of the two technical rounds of a virtual onsite. A software engineering intern candidate had to write a hash table in one of three one-hour onsite interviews. Another software engineer intern candidate had to explain how they would build a hash map; that report lists a coding test and then a phone interview of 45 minutes, and does not say which of the two had this question.

The reports do not name the operations, the key and value types, how collisions are handled, whether the table grows, limits, or how input reaches the code. Here the table maps keys made of 1 to 10 lowercase letters to integer values from 0 to 1,000,000,000, and supports put (add a key or replace its value), get (return the value, or -1 when the key is missing) and remove (delete the key; a missing key does nothing). A function gets the operations as three arrays of the same length, with at most 10,000 operations, and returns the results of the get operations in order. Writing the storage without the language's built-in map, dictionary or set is our reading of building your own hash table; tests cannot check it. Collision handling and growth are left to the solver; the editorial uses chaining and doubles the table when it fills up. One report asked for an explanation rather than code; here you write the code, in any of the site's languages, not only Swift.

Our version is about 70% the same as the reported question.

Build a hash table that maps string keys to integer values. Write the storage yourself: do not use your language's built-in hash table, map, dictionary or set to hold the entries.

You get three arrays of the same length: operations, keys and values. Run the operations from left to right. At index i, operations[i] is one of these:

  • "put": store values[i] under the key keys[i]. If the key is already in the table, replace its value.
  • "get": look up keys[i] and add its value to the result, or add -1 if the key is not in the table.
  • "remove": delete keys[i] and its value from the table. If the key is not in the table, do nothing.

Return the results of all "get" operations, in the order they ran.

How you spread the keys over your storage, and what you do when two different keys land in the same place, is up to you. Either way, every key must keep its own value.

Function

runHashTable(operations: String[], keys: String[], values: int[]) → int[]

Examples

Example 1

operations = ["put","put","get","put","get","get"]keys = ["apple","pear","apple","apple","apple","plum"]values = [3,7,0,5,0,0]return = [3,5,-1]

The first "get" finds 3 under "apple". The next "put" replaces that value with 5, so the second "get" returns 5. The key "plum" was never stored, so the last "get" returns -1.

Example 2

operations = ["put","put","get","get","remove","get","get"]keys = ["ab","ba","ab","ba","ab","ab","ba"]values = [1,2,0,0,0,0,0]return = [1,2,-1,2]

The keys "ab" and "ba" use the same letters, but they are different keys, so the first two lookups return 1 and 2. After "ab" is removed, looking it up returns -1, while "ba" still returns 2.

Example 3

operations = ["get","remove","put","get","remove","get"]keys = ["home","home","home","home","home","home"]values = [0,0,0,0,0,0]return = [-1,0,-1]

The table starts empty, so the first "get" returns -1, and removing the missing key changes nothing. Then "home" is stored with the value 0, which is a real value, so the next lookup returns 0. After the key is removed, the last lookup returns -1.

Constraints

  • 1 <= operations.length <= 10000
  • keys.length == operations.length
  • values.length == operations.length
  • Each operations[i] is "put", "get" or "remove".
  • 1 <= keys[i].length <= 10
  • keys[i] contains only lowercase English letters.
  • 0 <= values[i] <= 1000000000
  • When operations[i] is "get" or "remove", values[i] is 0 and is not used.

More Zillow interview questions

  • Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
  • First Unique Character in a StringOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2022
  • First N Fibonacci NumbersOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2021
  • LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
  • Blackjack Hand ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2016
  • FactorialPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2014
  • Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
  • Cumulative Fibonacci SumOA · PHONE SCREEN · Seen Aug 2021
  • Lowest Common Ancestor in a Binary TreePHONE SCREEN · Seen Sep 2019
  • Convert a String to a LongOA · Seen Jan 2018

Similar questions at other companies

  • Highest Bid Campaign MatcherStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions
  • In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
  • File Storage ServiceCresta · PHONE SCREENCresta interview questions
  • Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
  • Design a Food Rating SystemApple · PHONE SCREENApple interview questions
  • Parcel Event TrackingAirbnb · OAAirbnb interview questions
  • Hierarchical In-Memory File SystemClay · PHONE SCREEN
  • Design File SystemGoogle · PHONE SCREENGoogle interview questions
  • Numeric Poker OperationsRippling · PHONE SCREENRippling interview questions
All Zillow interview questionsSee Zillow hiring insights
Saved
class Solution {
    public int[] runHashTable(String[] operations, String[] keys, int[] values) {
        // Write your code here.
    }
}
Checking account…