FastPrepTrie and Heap Autocomplete System
Problems/Trie and Heap Autocomplete System

Trie and Heap Autocomplete System

Citadel logoCitadel● HardINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel Securities software engineering intern interview from spring 2026, in the one-on-one coding round with an engineer that came after the online assessment. The task was to build a data structure that mixes a trie with a heap, at the level of a hard practice problem.

The report gives no methods, examples or limits. Here, it is a search autocomplete: the trie holds past searches and their counts, each typed character shows the top 3 matches by count with ties in ASCII order, and '#' saves the typed sentence. You get the starting history and all the keystrokes at once and return the suggestions after each one, instead of calling class methods. The limits and the examples are ours.

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

Build a search autocomplete system as a hybrid data structure that combines a trie with a heap, and return the suggestions it shows after each character of keystrokes.

The search history starts with each sentences[i] searched times[i] times, and the current text starts empty. Then the characters of keystrokes are typed one at a time:

  • A letter or a space is added to the current text. Suggest the history sentences that start with the current text, at most 3 of them, from the most searched to the least. Sentences with the same count are listed in ASCII order, so a space comes before any letter. If no sentence matches, the list is empty.
  • '#' ends the current text as a finished search. Add 1 to its count, or add it to the history with a count of 1 if it is new. The current text becomes empty again, and the list for '#' is empty.

Return the suggestion lists in the order the characters are typed.

Note: a trie (prefix tree) is a tree where each edge adds one character, so all sentences that share a prefix share the path for that prefix.

Function

autocomplete(sentences: String[], times: int[], keystrokes: String) → List<List<String>>

Examples

Example 1

sentences = ["bid","buy","buy all","ask","bit"]times = [3,1,2,5,1]keystrokes = "buy#b"return = [["bid","buy all","bit"],["buy all","buy"],["buy all","buy"],[],["bid","buy","buy all"]]

After b, four sentences match. bid has 3 searches and buy all has 2. bit and buy tie at 1, and bit comes first in ASCII order, so only bit fits. The # raises buy to 2 searches, so the last b puts it before buy all and drops bit.

Example 2

sentences = ["ab","a b"]times = [1,1]keystrokes = "a c#a"return = [["a b","ab"],["a b"],[],[],["a b","a c","ab"]]

Every count is 1, so ASCII order decides, and a space comes before any letter. No sentence starts with a c, so that list is empty. The # saves a c, and it shows up for the last a.

Constraints

  • 1 <= sentences.length <= 100
  • times.length == sentences.length
  • 1 <= sentences[i].length <= 100
  • 1 <= times[i] <= 50
  • Each sentences[i] is made of lowercase English letters with a single space between words and no leading or trailing space. All sentences[i] are distinct.
  • 1 <= keystrokes.length <= 5000
  • keystrokes contains only lowercase English letters, spaces and '#'. Each '#' ends a non-empty sentence in the same format as sentences[i].
  • The current text never has more than 200 characters.

More Citadel Phone Screen questions

  • Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
  • Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
  • Square Root FunctionPHONE SCREEN · Seen Oct 2026
  • Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
  • Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
  • Currency Arbitrage CyclePHONE SCREEN · Seen Sep 2026
  • Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
  • Smart Queue of Latest PricesPHONE SCREEN · Seen Sep 2026
  • Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
  • Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Design Search Autocomplete SystemRoblox · PHONE SCREEN · ONSITE INTERVIEW
  • Design Search Autocomplete SystemBloomberg LP · PHONE SCREEN · ONSITE INTERVIEW
  • Design a Food Rating SystemApple · PHONE SCREEN
  • Design File SystemGoogle · PHONE SCREEN
  • Long-ID Store Without HashingAdobe · PHONE SCREEN
  • Implement TrieOptiver · PHONE SCREEN
  • Word Dictionary with WildcardsDatadog · PHONE SCREEN
  • Design a File System with PathsAirbnb · PHONE SCREEN
  • Word Dictionary with Wildcard FindAmazon · ONSITE INTERVIEW
  • Implement a TrieMicrosoft · ONSITE INTERVIEW

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
  • Citadel SWE Intern First-Round Questions: 20 Experiences
See Citadel hiring insights
Saved
class Solution {
    public List<List<String>> autocomplete(String[] sentences, int[] times, String keystrokes) {
      // Write your code here.
    }
}
Checking account…