FastPrepPrefix Word Dictionary
Problems/Prefix Word Dictionary

Prefix Word Dictionary

Bloomberg LP logoBloomberg LP● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A candidate's report on a Bloomberg screening round that precedes the onsite interviews, in a post labelled SSE, includes this task: build a dictionary that takes lowercase words and can list every word that begins with a given prefix. The report shows one example, two words that share a prefix, and the author's own trie code, in which two lines are marked as mistakes. The round also had a separate tree validation question and a question about a past production problem. The author was rejected. No limits, answer order or rule for repeated words is given.

Our choices: the calls come as two lists, operations and arguments, in one function. Words and prefixes use lowercase letters. A word equal to the prefix matches, an empty prefix matches every word, and adding a word again changes nothing. Each answer lists matching words once, in alphabetical order. A run has up to 2,000 operations, words of up to 12 letters, and at most 1,000 words in all answers together.

The judged task matches the report at about 85%.

You are building a dictionary of lowercase words that can answer prefix questions. For example, after adding "cart", "care" and "dog", the prefix "car" matches "care" and "cart".

You get two arrays of the same length, operations and arguments. Run them from first to last on a dictionary that starts empty. operations[i] is the name of operation i and arguments[i] is its string.

  • "add": arguments[i] is a word. Put it in the dictionary. Adding a word that is already there changes nothing.
  • "queryPrefix": arguments[i] is a prefix. Find every word in the dictionary right now that starts with this prefix.

A word starts with a prefix when its first letters are exactly the prefix. A word starts with itself, and the empty prefix "" is the start of every word.

Return a list with one answer for each "queryPrefix", in the order they run. Each answer is the list of matching words, each listed once, in alphabetical order. Compare letter by letter; a word that is a prefix of another word comes first, so "pen" is before "pencil". If no word matches, the answer is an empty list. If there is no "queryPrefix", return an empty list.

Function

runPrefixDictionary(operations: String[], arguments: String[]) → String[][]

Examples

Example 1

operations = ["add","add","add","queryPrefix"]arguments = ["cart","care","dog","car"]return = [["care","cart"]]

The dictionary holds "cart", "care" and "dog". Two of them start with "car". In alphabetical order, "care" comes before "cart" (the fourth letters are e and t). The answer is [["care","cart"]].

Example 2

operations = ["add","add","add","queryPrefix","queryPrefix","queryPrefix"]arguments = ["pencil","pen","pen","pen","pe","x"]return = [["pen","pencil"],["pen","pencil"],[]]

Adding "pen" a second time changes nothing, so it is listed once. A word counts as starting with a prefix when it equals the prefix, so "pen" is listed for the prefix "pen", before the longer word "pencil". The prefix "pe" matches the same two words. No word starts with "x", so that answer is an empty list. The answer is [["pen","pencil"],["pen","pencil"],[]].

Example 3

operations = ["add","add","queryPrefix","add","queryPrefix"]arguments = ["tea","ten","","tee","te"]return = [["tea","ten"],["tea","tee","ten"]]

The empty prefix "" matches every word, so the first query lists "tea" and "ten". After "tee" is added, the prefix "te" matches all three words in alphabetical order. The answer is [["tea","ten"],["tea","tee","ten"]].

Constraints

  • 1 <= operations.length <= 2000
  • arguments.length == operations.length
  • Each operations[i] is "add" or "queryPrefix".
  • For "add", arguments[i] is a word of 1 to 12 lowercase English letters. For "queryPrefix", arguments[i] is a prefix of 0 to 12 lowercase English letters.
  • The answers together contain at most 1000 words in total.

More Bloomberg LP Phone Screen questions

  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
  • Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
  • Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Design File SystemGoogle · PHONE SCREENGoogle interview questions
  • Long-ID Store Without HashingAdobe · PHONE SCREENAdobe interview questions
  • Implement TrieOptiver · PHONE SCREENOptiver interview questions
  • Word Dictionary with WildcardsDatadog · PHONE SCREENDatadog interview questions
  • Design Search Autocomplete SystemRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Word Dictionary with Wildcard FindAmazon · ONSITE INTERVIEW
  • Implement a TrieMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Add Word and Suffix SearchAnduril · ONSITE INTERVIEWAnduril interview questions
  • In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
  • File System PathsCapital One · ONSITE INTERVIEWCapital One interview questions

Bloomberg LP interview experiences

  • Bloomberg SWE Phone Screen and Onsite: 1 Experience
  • Bloomberg SWE Phone Screens with Two Teams: 1 Experience
  • Bloomberg AI Interview, Hiring Level Not Reported: 2 Experiences
  • Bloomberg Experienced SWE AI Coding Interviews: 2 Experiences
  • Bloomberg New Grad AI-Assisted Coding Rounds: 3 Experiences
  • Bloomberg New Grad SWE AI-Assisted Coding Rounds: 1 Experience
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public String[][] runPrefixDictionary(String[] operations, String[] arguments) {
        // Write your code here.
    }
}
Checking account…