FastPrepLongest Dictionary Word from Nine Letters
Problems/Longest Dictionary Word from Nine Letters

Longest Dictionary Word from Nine Letters

Google logoGoogle● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives a dictionary, nine available letters, each letter used once, the goal of the longest word, and a frequency-vector approach. It does not say how to break ties, what to return when nothing matches, the input limits, or a function signature. We added those without changing the reported task.

You are given an array of lowercase dictionary words words and a lowercase string letters containing exactly nine characters. Return the longest word that can be built using the characters in letters.

Each occurrence in letters may be used at most once, so repeated characters in a word require the same number of occurrences in letters. If several buildable words have the same maximum length, return the one that appears earliest in words. Return the empty string when no word can be built.

Function

longestWord(words: String[], letters: String) → String

Examples

Example 1

words = ["cat","bt","hat","tree"]letters = "atachxxxx"return = "cat"

Both cat and hat can be built and have length three. Because cat appears first, it wins the tie.

Example 2

words = ["hello","world","hold","owl"]letters = "ollheabcd"return = "hello"

The letters contain exactly the h, e, two ls, and o needed for hello.

Example 3

words = ["aaa","bb"]letters = "abcdefghi"return = ""

Neither word is buildable because the nine letters do not contain enough copies of its repeated character.

Constraints

  • 1 <= words.length <= 100000.
  • 1 <= words[i].length <= 100.
  • The sum of all word lengths is at most 1000000.
  • letters.length == 9.
  • words[i] and letters contain only lowercase English letters.

More Google Onsite Interview questions

  • 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
  • Route Pattern MatcherPHONE SCREEN · ONSITE 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

  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
  • K-Second Message SuppressionMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW
  • Find Nodes with Invalid Parent LevelsZip · ONSITE INTERVIEWZip interview questions
  • Count Word FrequenciesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Most Voted CandidateExpedia · ONSITE INTERVIEWExpedia interview questions
  • List Each Name Once, AlphabeticallyDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Shortest Uncommon SubstringAirbnb · ONSITE INTERVIEWAirbnb interview questions

Interview reports that mention this question

  • Google Intern Grid and Tree Rounds: 7 Experiences (Part 2 of 8)

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
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String longestWord(String[] words, String letters) {
      // Write your code here.
    }
}
Checking account…