You are given a list of products, where each product is a string. You are also given a searchWord. After each character typed, return the top k suggestions of product names that match the typed prefix.
Each product also has an associated popularity score (Map
You must return suggestions after each character of searchWord. Handle up to 1e5 products and optimize for performance.
Examples
01 · Example 1
products = ["apple", "appetizer", "application", "app", "apply", "banana", "appstore"] popularity = [["apple", "80"], ["appetizer", "70"], ["application", "90"], ["app", "90"], ["apply", "85"], ["banana", "60"], ["appstore", "90"]] searchWord = "app" k = 3 return = [["app", "application", "appstore"], ["app", "application", "appstore"], ["app", "application", "appstore"]]
~.~
More Google problems
- Consolidate On-Call RotationsOA · Seen Jun 2026
- Detonate Bombs with Chain ReactionsONSITE INTERVIEW · Seen May 2026
- Evaluate a Nested Math ExpressionONSITE INTERVIEW · Seen May 2026
- Tic-Tac-Toe Game StatusPHONE SCREEN · Seen May 2026
- Longest Dictionary TokenizationPHONE SCREEN · Seen May 2026
- Minimum Cars for Rental RequestsONSITE INTERVIEW · Seen Apr 2026
- Shortest Path with Mandatory WaypointONSITE INTERVIEW · Seen Apr 2026
- Count Divisible Coin SelectionsOA · Seen Dec 2025
public String[][] searchSuggestions(String[] products, String[][] map, String searchWord, int k) {
// write your code here
}
products["apple", "appetizer", "application", "app", "apply", "banana", "appstore"]
popularity[["apple", "80"], ["appetizer", "70"], ["application", "90"], ["app", "90"], ["apply", "85"], ["banana", "60"], ["appstore", "90"]]
searchWord"app"
k3
expected[["app", "application", "appstore", "app", "application", "appstore", "app", "application", "appstore"]]
sign in to submit