FastPrepSearch Suggestions with a Prefix Tree
Problems/Search Suggestions with a Prefix Tree

Search Suggestions with a Prefix Tree

Citadel logoCitadel● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel intern onsite interview. The report names a search-suggestions exercise and a prefix-tree approach. It leaves out the exact cap on suggestions, the ordering, the interface, the examples, and the limits. Our version is about 85% the same as the reported question.

You are given an array of distinct lowercase product names products and a lowercase search string query.

After each character of query is typed, form the accumulated non-empty prefix and return up to three product names that begin with that prefix.

  • Order matching products lexicographically.
  • If more than three products match, keep the first three.
  • Once a prefix has no matches, that prefix and every longer prefix return an empty list.

Return one suggestion list for every character of query, in order.

Function

searchSuggestions(products: String[], query: String) → String[][]

Examples

Example 1

products = ["mobile","mouse","moneypot","monitor","mousepad"]query = "mouse"return = [["mobile","moneypot","monitor"],["mobile","moneypot","monitor"],["mouse","mousepad"],["mouse","mousepad"],["mouse","mousepad"]]

The first two prefixes are m and mo, whose first three lexicographic matches are mobile, moneypot, and monitor. From mou onward, only mouse and mousepad match.

Example 2

products = ["bags","baggage","banner","box","cloths"]query = "bags"return = [["baggage","bags","banner"],["baggage","bags","banner"],["baggage","bags"],["bags"]]

The prefixes b and ba have at least three matches. Prefix bag has two matches, and the full prefix bags has one.

Example 3

products = ["alpha","alpine","beta"]query = "cat"return = [[],[],[]]

No product begins with c, so every prefix returns an empty list.

Constraints

  • 1 <= products.length <= 100000.
  • Every product is a distinct non-empty lowercase English string.
  • 1 <= query.length <= 100000.
  • The total number of characters across all products is at most 10^6.

More Citadel Onsite Interview questions

  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Removal PoolONSITE INTERVIEW · Seen Sep 2026
  • Centered K-by-K Submatrix SumsONSITE INTERVIEW · Seen Aug 2026
  • Traverse Interior Matrix Cells in Row-Major OrderONSITE INTERVIEW · Seen Aug 2026
  • Limit Order Book Matching EnginePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Fixed-Capacity Circular BufferONSITE INTERVIEW · Seen Jun 2026
  • Stock Trading with a Fee and a CooldownONSITE INTERVIEW · Seen May 2026
  • Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
  • 2048 Simulation and Board CodecONSITE INTERVIEW · Seen Jan 2026

Similar questions at other companies

  • Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Shell Path AutocompleteFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
  • Remove Prefix StringsRoblox · PHONE SCREENRoblox interview questions
  • Every Distinct Substring in OrderAdobe · PHONE SCREENAdobe interview questions
  • Top K Query SuggestionsMicrosoft · PHONE SCREENMicrosoft interview questions
  • Find the Words for Each PrefixDocuSign · PHONE SCREENDocuSign interview questions
  • Suggested ProductsSquarepoint Capital · OASquarepoint Capital interview questions
  • Find All Word Occurrences in TextSentry · PHONE SCREENSentry interview questions

Interview reports that mention this question

  • Citadel SWE Intern First-Round Questions: 20 Experiences

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public String[][] searchSuggestions(String[] products, String query) {
      // write your code here
    }
}
Checking account…