FastPrepCheck Unordered Letter Coverage

Check Unordered Letter Coverage

NVIDIA logoNVIDIA● EasyFULLTIMEPHONE SCREEN
Learn

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) → boolean

Examples

Example 1

s = "aba"t = "bax"return = true

The 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 = false

The required letter z does not occur in t.

Example 3

s = "zz"t = "z"return = true

Only 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 a through z.

More NVIDIA problems

See NVIDIA hiring insights
public boolean containsUnorderedLetters(String s, String t) {
    // Return whether t satisfies the required letter matching.
}
s"aba"
t"bax"
expectedtrue
Checking account…