Can One Dictionary Word Supply the Target Letters?
Updated
Problem statement
Given a nonempty string target and an array words, return whether at least one word can supply every letter occurrence of the target.
For this exercise, assume all characters are lowercase English letters and the target must be constructed by rearranging character occurrences from one candidate word. Each occurrence is used at most once. Do not concatenate whole words or combine letters from several candidates.
For this exercise, assume candidates are checked independently. Return false if no candidate supplies the target, including an empty dictionary.
Function
canSupplyTarget(target: String, words: String[]) → booleanExamples
Example 1
target = "aab"words = ["ab","bbaa"]return = trueThis example can construct the target from one supplying candidate.
Example 2
target = "aa"words = ["a","ab"]return = falseThis example cannot reuse the single a in any candidate.
Example 3
target = "ab"words = ["a","b"]return = falseThis example does not combine letters across different dictionary words.
Constraints
- For this exercise, assume
1 <= target.length <= 500,0 <= words.length <= 200and1 <= words[i].length <= 2000. - All strings contain lowercase 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
- Greedy Grid Word Occurrences with No Reused CellsPHONE SCREEN · Seen Apr 2022
- Word Path Moving Only Right or DownPHONE SCREEN · Seen Apr 2022
- First Dictionary Word from Note LettersPHONE SCREEN · Seen Mar 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