FastPrepDictionary Words With a Prefix
Problems/Dictionary Words With a Prefix

Dictionary Words With a Prefix

Google logoGoogle● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two Google reports describe the same task: list the dictionary words that begin with a given prefix. One of them also brings up the empty-prefix case, and its example used capitalized words. Example 4 is that example in lowercase, with the matches sorted. Neither report gives limits, a character set, or an output order. Here, words are unique lowercase strings, matches come back in alphabetical order, and an empty prefix matches every word. The limits are our choice. Our version is about 92% the same as the reported questions.

Given an array of unique lowercase English words dictionary and a lowercase string prefix, return every dictionary word that starts with prefix.

Return matching words in alphabetical order. An empty prefix matches every word.

Function

wordsWithPrefix(dictionary: String[], prefix: String) → String[]

Examples

Example 1

dictionary = ["apple","app","bat"]prefix = "app"return = ["app","apple"]

Both app and apple begin with app, and lexicographic order places the shorter word first.

Example 2

dictionary = ["dog","cat","door"]prefix = "z"return = []

No word begins with z.

Example 3

dictionary = ["beta","alpha","alpine"]prefix = ""return = ["alpha","alpine","beta"]

The empty prefix matches every word, so all words are sorted.

Example 4

dictionary = ["google","good","grape"]prefix = "goo"return = ["good","google"]

Both good and google start with goo, but grape does not. good comes first because its fourth letter, d, comes before g.

Constraints

  • 0 <= dictionary.length <= 100000.
  • 1 <= dictionary[i].length <= 100.
  • 0 <= prefix.length <= 100.
  • All words are unique and all strings contain only lowercase English letters.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEWPalantir interview questions
  • Three Word Suggestions for Every PrefixThe Walt Disney Company · ONSITE INTERVIEWThe Walt Disney Company interview questions
  • Count Proper Prefix MatchesAT&T · OAAT&T interview questions
  • Product Record SearchWells Fargo · OAWells Fargo interview questions
  • Find the Words for Each PrefixDocuSign · PHONE SCREENDocuSign interview questions
  • Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
  • Sort Topic Names by Prefix and NumberPerplexity AI · ONSITE INTERVIEWPerplexity AI interview questions
  • Sort Words by LengthMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Sort Sentence WordsInfosys · ONSITE INTERVIEWInfosys interview questions
  • Check AnagramsDeloitte · ONSITE INTERVIEWDeloitte interview questions

Interview reports that mention this question

  • Google SWE III ML Experienced Loops: 10 Experiences (Part 3 of 4)
  • Google PhD AI/ML Onsite Mahjong and Prefix Search: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[] wordsWithPrefix(String[] dictionary, String prefix) {
        // write your code here
    }
}
Checking account…