Autocomplete Words by Prefix
Updated
Problem statement
Given a vocabulary array words and a string prefix, return every distinct vocabulary word that starts with prefix.
Matching is case-sensitive. Return the results in lexicographic order.
Function
autocomplete(words: String[], prefix: String) → String[]Examples
Example 1
words = ["dog","door","deer","doom","door"]prefix = "do"return = ["dog","doom","door"]The three distinct matching words are returned once in lexicographic order.
Example 2
words = ["apple","banana"]prefix = "cat"return = []No vocabulary word begins with cat.
Constraints
0 <= words.length <= 1000000 <= words[i].length, prefix.length <= 100- Every word and the prefix contain only lowercase English letters.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Compress Consecutive Integer RangesDocuSign · ONSITE INTERVIEWDocuSign interview questions
- Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
- Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW
- Type-Ahead Prefix MatchesNavan · ONSITE INTERVIEWNavan interview questions
- Count Word FrequenciesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Most Voted CandidateExpedia · ONSITE INTERVIEWExpedia interview questions
- Anagrams of a Word in a Word ListZillow · PHONE SCREEN · ONSITE INTERVIEWZillow interview questions
- Travelers per Consecutive City TripletUber · ONSITE INTERVIEWUber interview questions
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions