← 返回 roblox 的题目列表Design Search Autocomplete System
类型:qbank
Design an autocomplete system that returns top suggestions for the current prefix and learns completed queries.
Examples
Example 1:
Input: queries = ["roblox studio","roblox","roadblocks","roblox studio","roblox game","roblox"], timestamps = [5,1,7,3,4,2], prefixes = ["rob","robl","road","x"]
Output: [["roblox","roblox studio","roblox game"],["roblox","roblox studio","roblox game"],["roadblocks"],[]]
Explanation:
roblox and roblox studio each appear twice, so the earlier first timestamp puts roblox first. roblox game appears once.
Example 2:
Input: queries = ["alpha","alpine","alpha","alpine"], timestamps = [10,3,2,8], prefixes = ["al"]
Output: [["alpha","alpine"]]
Explanation:
Both queries appear twice. alpha has earliest timestamp 2, while alpine has earliest timestamp 3.
Example 3:
Input: queries = ["aba","abb","aba","abb"], timestamps = [1,1,5,7], prefixes = ["ab"]
Output: [["aba","abb"]]
Explanation:
The count and earliest timestamp both tie, so lexicographic order breaks the tie.
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