First Dictionary Word from Note Letters
Updated
Problem statement
You are given a string note and a list of dictionary words words, in order. Return the first word in the list that you can spell using letters from note.
"First" means the word with the smallest index in words. Assume all characters are lowercase English letters. Each letter in the note can be used at most once when you spell one word. The letters you need can be anywhere in the note, in any order. Check each word on its own against the full note: a word that cannot be spelled does not use up any letters.
Every dictionary word has at least one letter. The note and the list may be empty. If no word can be spelled, return the empty string.
Function
firstWord(note: String, words: String[]) → StringExamples
Example 1
note = "tacappse"words = ["cat","bird","apple"]return = "cat"The note contains c, a and t, so the first word, cat, can be formed.
Example 2
note = "tacjbcebef"words = ["cat","baby","bird","fruit"]return = "cat"The note contains c, a and t, so cat can be formed, and it comes first in the list.
Example 3
note = "bacdrigb"words = ["cat","baby","bird","fruit"]return = "bird"cat needs a t and baby needs a y, and the note has neither. bird can be formed from b, i, r and d, even though those letters are not next to each other.
Constraints
0 <= note.length <= 20000 <= words.length <= 200- Each word contains from
1through500lowercase English letters.
More Compass International Holdings Phone Screen questions
- Decode StringPHONE SCREEN · Seen Oct 2026
- Lowest Common Ancestors in a Parent DAGPHONE SCREEN · Seen Apr 2022
- Can One Dictionary Word Supply the Target Letters?PHONE SCREEN · Seen Apr 2022
- Greedy Grid Word Occurrences with No Reused CellsPHONE SCREEN · Seen Apr 2022
- Word Path Moving Only Right or DownPHONE SCREEN · Seen Apr 2022
- Word Path Moving Only Up or RightPHONE SCREEN · Seen Feb 2022
- Top Five Stock Records in a Date RangePHONE SCREEN · Seen Oct 2021
- Wrap Words from Existing Text LinesPHONE SCREEN · Seen Apr 2021
- All Common Ancestors in a Parent GraphPHONE SCREEN · Seen Jan 2021
- Nodes With Zero or Three ParentsPHONE SCREEN · Seen Jan 2021
Similar questions at other companies
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- First Letter to Appear TwiceCisco · PHONE SCREENCisco interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
- Summarize Server Healthcheck LogsNVIDIA · PHONE SCREENNVIDIA interview questions
- Known Words Matching Phone DigitsLinkedIn · PHONE SCREENLinkedIn interview questions
- First Non-Repeated CharacterDell Technologies · PHONE SCREENDell Technologies interview questions
- Convert an Entry List to a MapEPAM · PHONE SCREENEPAM interview questions
- First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions