Choose Five Words with 25 Distinct Letters
Updated
Problem statement
You are given distinct lowercase five-letter strings. Choose exactly five different strings so their combined 25 characters are all distinct.
Return the lexicographically smallest sorted array of five words among all valid choices. Return an empty array when no choice exists.
A word containing a repeated character can never be chosen.
Function
chooseFiveDisjointWords(words: String[]) → String[]Examples
Example 1
words = ["abcde","fghij","klmno","pqrst","uvwxy","zzzzz"]return = ["abcde","fghij","klmno","pqrst","uvwxy"]The first five words use 25 different letters.
Example 2
words = ["abcde","afghi","jklmn","opqrs","tuvwx"]return = []The only five words repeat a, so no choice works.
Example 3
words = []return = []Fewer than five words cannot form a choice.
Constraints
0 <= words.length <= 200.- Every word has length five, contains lowercase English letters, and words are distinct.
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
- Maximum Unique-Character Word SubsetMeta · ONSITE INTERVIEWMeta interview questions
- Generate All Valid Word AbbreviationsSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Optimal Account BalancingAmazon · ONSITE INTERVIEW
- All Balanced Strings from Minimum Parenthesis InsertionsRubrik · ONSITE INTERVIEWRubrik interview questions
- N-Queens Solution CounteBay · ONSITE INTERVIEWeBay interview questions
- N-Queens Solution CountOptimus Information · ONSITE INTERVIEWOptimus Information interview questions
- Remove Invalid ParenthesesMygate · ONSITE INTERVIEWMygate interview questions
- Count and Score Distinct Hat AssignmentsRoblox · ONSITE INTERVIEWRoblox interview questions
- Maximum Currency Conversion Along a Simple PathRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Minimum Stickers to Form a Target StringByteDance · ONSITE INTERVIEWByteDance interview questions