First Dictionary Word Containing Target Letters
Updated
Problem statement
You are given a nonempty string target and an array words. Return the first word in words whose characters can form target. The word may have extra characters left over.
All characters are lowercase English letters. Build target by rearranging characters from one word only. Each character in that word can be used at most once. Do not join whole words together or mix letters from different words.
Check each word on its own. The first word means the one with the smallest index in words. If no word can form target, return the empty string. This includes the case where words is empty.
Function
firstContainingWord(target: String, words: String[]) → StringExamples
Example 1
target = "sky"words = ["cry","edt","srk","srrfkrey"]return = "srrfkrey"cry has no s or k. edt has none of the letters. srk has no y. srrfkrey has s, k and y, and its extra letters are fine. So the answer is "srrfkrey".
Example 2
target = "aab"words = ["ab","bbaa","aaab"]return = "bbaa"target needs two a letters and one b. ab has only one a. bbaa has two of each, which is enough. It comes first, so the answer is "bbaa".
Example 3
target = "abc"words = ["ab","bc"]return = ""ab has no c, and bc has no a. No word can form target, so the answer is the empty string.
Constraints
1 <= target.length <= 5000 <= words.length <= 2001 <= words[i].length <= 2000- All strings contain lowercase English letters.
More Atlassian Phone Screen questions
- Merge Overlapping IntervalsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Tennis Court SchedulingPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Implement a Rate LimiterPHONE SCREEN · Seen Oct 2026
- Longest Consistent Activity StreakPHONE SCREEN · Seen Sep 2026
- Music Player Operation SequencePHONE SCREEN · Seen Sep 2026
- Underline Shortest Unique SubstringsPHONE SCREEN · Seen Aug 2026
- Can a Dictionary Word Be Formed from Note Letters?PHONE SCREEN · Seen Feb 2026
- Word Path Moving Only Right or DownPHONE SCREEN · Seen Feb 2026
- Ordered Badge Entry and Exit ViolationsPHONE SCREEN · Seen Aug 2025
- Two Sum with an Ordered Index PairPHONE SCREEN · Seen Aug 2025
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