FastPrepDesign Search Autocomplete System
Problems/Design Search Autocomplete System

Design Search Autocomplete System

Roblox logoRoblox● HardFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Three reports written by their authors, from Roblox interviews, back this version. The reports describe counts of queries, timestamps, prefix lookup, ranking by frequency first, and breaking ties by the earliest timestamp. We chose the final tie break in dictionary order and what happens with an empty prefix. Our version is about 80% the same as the reported question.

You are given three arrays:

  • queries[i] is a search query issued by a user.
  • timestamps[i] is the time when queries[i] was issued.
  • prefixes[j] is a prefix typed into an autocomplete box.

For each prefix, return every distinct query that starts with that prefix, ranked like this:

  1. A query issued more times comes first.
  2. If counts tie, the query with the smaller earliest timestamp comes first. A query's earliest timestamp is the first time it was ever issued.
  3. If both still tie, the lexicographically smaller query comes first.

Return one ranked list per prefix, in the same order as prefixes. If a prefix has no matching query, return an empty list for that prefix. The empty prefix matches every distinct query.

This is the batch version of the classic search autocomplete design question. One way to solve it is a Trie built from the query strings. The node where a query ends stores that query's count and earliest timestamp. For each prefix, go to its node, collect every query in the subtree below it, and rank them with the rules above. In a live interview, ask whether the output should include all matching queries or only the top k suggestions.

Function

autocomplete(queries: String[], timestamps: int[], prefixes: String[]) → List<List<String>>

Examples

Example 1

queries = ["roblox studio", "roblox", "roadblocks", "roblox studio", "roblox game", "roblox"]timestamps = [5, 1, 7, 3, 4, 2]prefixes = ["rob", "robl", "road", "x"]return = [["roblox", "roblox studio", "roblox game"], ["roblox", "roblox studio", "roblox game"], ["roadblocks"], []]

"roblox" and "roblox studio" each appear twice, so they rank ahead of "roblox game", which appears once. Among the count-2 queries, "roblox" was first issued at timestamp 1 and "roblox studio" at timestamp 3, so "roblox" comes first. Prefixes "rob" and "robl" both match these three queries. "road" matches only "roadblocks", and "x" matches nothing.

Example 2

queries = ["alpha", "alpine", "alpha", "alpine"]timestamps = [10, 3, 2, 8]prefixes = ["al"]return = [["alpha", "alpine"]]

Both queries appear twice, so the earliest-timestamp tie-break applies: "alpha" has earliest timestamp 2 while "alpine" has earliest timestamp 3, so "alpha" ranks first.

Example 3

queries = ["aba", "abb", "aba", "abb"]timestamps = [1, 1, 5, 7]prefixes = ["ab"]return = [["aba", "abb"]]

Both queries appear twice and share earliest timestamp 1, so the lexicographic tie-break orders "aba" before "abb".

Constraints

  • queries.length == timestamps.length
  • 0 <= queries.length <= 10^5
  • 1 <= prefixes.length <= 10^4
  • 1 <= queries[i].length <= 100
  • 0 <= prefixes[i].length <= 100
  • 0 <= timestamps[i] <= 10^9
  • queries[i] contains printable ASCII characters.
  • prefixes[i] is empty or contains printable ASCII characters.

More Roblox Phone Screen questions

  • Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
  • Rate Limit by Multiple Request FieldsPHONE SCREEN · Seen Oct 2026
  • Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Time-Aware Search AutocompletePHONE SCREEN · Seen Oct 2026
  • Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 2026
  • Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026

Similar questions at other companies

  • Trie and Heap Autocomplete SystemCitadel · PHONE SCREENCitadel interview questions
  • Design Search Autocomplete SystemBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Design a Food Rating SystemApple · PHONE SCREENApple interview questions
  • Word Dictionary with Wildcard FindAmazon · ONSITE INTERVIEW
  • Design File SystemGoogle · PHONE SCREENGoogle interview questions
  • Implement a TrieMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Add Word and Suffix SearchAnduril · ONSITE INTERVIEWAnduril interview questions
  • Trie: Add and Search WordsAdobe · ONSITE INTERVIEWAdobe interview questions
  • In-Memory Directory and File OperationsSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions
  • Implement TrieOptiver · PHONE SCREENOptiver interview questions

Roblox interview experiences

  • Roblox OA: What It Tests (2026)
  • Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
  • Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
  • Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
  • Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
  • Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)
All Roblox interview questionsSee Roblox hiring insights
Saved
class Solution {
    public List<List<String>> autocomplete(String[] queries, int[] timestamps, String[] prefixes) {
      // write your code here
    }
}
Checking account…