FastPrepFind the Words for Each Prefix
Problems/Find the Words for Each Prefix

Find the Words for Each Prefix

DocuSign logoDocuSign● MediumINTERNPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A report from September 2018 describes a phone screen with two questions answered out loud, without code. This problem is based on the first one, which was about speeding up a search for all words in a list that share a given starting string.

The report gives no input format, result order, limits or examples. Here you answer many prefixes at once, because a fast lookup pays off when the same words are searched again and again. Each answer lists its words in alphabetical order. There are up to 3,000 different lowercase words and 1,000 prefixes. The answers hold at most 1,000 words in total. We wrote the examples.

Our version is about 80% the same as the reported question.

You are given an array of different words words and an array of queries prefixes.

For each prefix, find every word that starts with it. A word starts with a prefix when its first letters are exactly the prefix; a word also starts with itself.

Return a list with one entry per prefix, in the same order as prefixes. Each entry lists the matching words in alphabetical order, or is empty when no word matches. If a prefix appears more than once, answer it each time.

Function

wordsForPrefixes(words: String[], prefixes: String[]) → List<List<String>>

Examples

Example 1

words = ["sign","signal","seal","sigma","send"]prefixes = ["sig","se","x"]return = [["sigma","sign","signal"],["seal","send"],[]]

Words starting with sig: sign, signal and sigma, listed alphabetically as sigma, sign, signal. Words starting with se: seal and send. No word starts with x, so that list is empty.

Example 2

words = ["doc","docs","dock"]prefixes = ["doc","docks"]return = [["doc","dock","docs"],[]]

All three words start with doc, including doc itself. No word starts with docks, because docks is longer than every word that begins with dock.

Example 3

words = ["a","ab","b"]prefixes = ["a","b","a"]return = [["a","ab"],["b"],["a","ab"]]

The prefix a appears twice, so its list appears twice: a and ab. The prefix b matches only b.

Constraints

  • 1 <= words.length <= 3000
  • 1 <= prefixes.length <= 1000
  • 1 <= words[i].length, prefixes[j].length <= 10
  • Every word and prefix contains only lowercase English letters.
  • All words are different.
  • The returned lists hold at most 1000 words in total.

More DocuSign Phone Screen questions

  • Symmetric Binary TreePHONE SCREEN · Seen Oct 2026
  • Union Area of Two RectanglesPHONE SCREEN · Seen Oct 2026
  • Execute Cursor-Based Text Editor OperationsPHONE SCREEN · Seen Sep 2026
  • Minimize Array Sum After K Halving OperationsPHONE SCREEN · Seen Sep 2026
  • Fizz and Buzz Words From 1 to nPHONE SCREEN · Seen Sep 2026
  • Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Rain Kept Between WallsPHONE SCREEN · Seen Mar 2026
  • Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
  • Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
  • Rebuild a Trip From Flight TicketsPHONE SCREEN · Seen Apr 2019

Similar questions at other companies

  • Find All Word Occurrences in TextSentry · PHONE SCREENSentry interview questions
  • Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
  • Lexicographic Search SuggestionsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Product Record SearchWells Fargo · OAWells Fargo interview questions
  • Find Unmet Users With Shared InterestsPalantir · ONSITE INTERVIEWPalantir interview questions
  • Merge Weekday and Time IntervalsNextdoor · PHONE SCREENNextdoor interview questions
  • Group AnagramsWorkday · PHONE SCREEN
  • Aggressive CowsAmazon · PHONE SCREEN
  • Group AnagramsEPAM · PHONE SCREENEPAM interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions

Interview reports that mention this question

  • DocuSign SWE Intern Interviews: 27 Experiences (Part 2 of 2)

DocuSign interview experiences

  • DocuSign SWE Intern OA Questions: 53 Experiences (Part 1 of 2)
All DocuSign interview questionsSee DocuSign hiring insights
Saved
class Solution {
    public List<List<String>> wordsForPrefixes(String[] words, String[] prefixes) {
        // Write your code here.
    }
}
Checking account…