Dictionary Words Formable From Letters
Updated
Problem statement
Given a lowercase dictionary dictionary and a lowercase string letters, return every dictionary word that can be built from the available letters.
Each occurrence in letters may be used at most once per word. Preserve dictionary order, preserve repeated dictionary entries, and return an empty array when no word is buildable. The empty word can be built from any supplied letters, including none.
Function
wordsFromLetters(dictionary: String[], letters: String) → String[]Examples
Example 1
dictionary = ["cat","act","taco","dog"]letters = "tac"return = ["cat","act"]Both cat and act use exactly the three available letters. taco needs an extra letter and dog uses unavailable letters.
Example 2
dictionary = ["a","aa","aaa"]letters = "aa"return = ["a","aa"]The two available copies of a can build the first two words but not the third.
Example 3
dictionary = []letters = "abc"return = []An empty dictionary contains no words to return.
Constraints
0 <= dictionary.length <= 100000.0 <= dictionary[i].length,letters.length <= 100000.- The total length of all dictionary words is at most
1000000. - 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
- Markov Transition Counts and ProbabilitiesRetool · ONSITE INTERVIEWRetool interview questions
- Deduplicated Query RegistrationDatadog · ONSITE INTERVIEWDatadog interview questions
- Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
- Ransom NoteThe Walt Disney Company · OA · PHONE SCREENThe Walt Disney Company interview questions
- K-th Non-Repeating Character IndexBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Minimum Deletions to Make Every Letter Count EvenMarshall Wace · OAMarshall Wace interview questions
- Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions
- Count One-Swap Number PairsCapital One · OACapital One interview questions
- How Many Sentences?Chubb · OAChubb interview questions
- Perfect SubstringsVisa · OAVisa interview questions