Check Unordered Letter Coverage
Problem statement
Given two strings s and t, return true if every distinct letter appearing in s appears at least once in t. Otherwise, return false.
For this exercise, assume order and repetition counts are irrelevant. Multiple occurrences of the same letter in s require only one occurrence in t. Extra letters in t are allowed.
For this exercise, an empty s is covered by every target, including an empty target. A nonempty s is not covered by an empty t.
What the interview report shared
The report describes a set-based attempt and an unresolved discussion about worst-case running time. Explain the complexity of the data structure you choose.
Function
containsUnorderedLetters(s: String, t: String) → booleanExamples
Example 1
s = "aba"t = "bax"return = trueThe distinct required letters are a and b. Both occur in t; the repeated a does not require another occurrence.
Example 2
s = "az"t = "abc"return = falseThe required letter z does not occur in t.
Example 3
s = "zz"t = "z"return = trueOnly the distinct letter z must be present. Counts and order do not affect this decision.
Constraints
- For this exercise, assume
0 <= s.length, t.length <= 1000. - For this exercise, both strings contain only lowercase English letters
athroughz.