FastPrepCheck Ordered Letter Containment

Check Ordered Letter Containment

NVIDIA logoNVIDIA● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given two strings s and t, return true if all character occurrences of s can be selected from t in the same order. Otherwise, return false.

For this exercise, assume each character occurrence of s must match a different position in t. The selected target positions must be strictly increasing. You may skip other characters of t; the selected positions do not have to be consecutive.

For this exercise, the empty string is contained in every target, including an empty target. A nonempty s is not contained in an empty t.

What the interview report shared

The report describes ordered matching between two strings and a two-pointer approach.

Function

containsOrderedLetters(s: String, t: String) → boolean

Examples

Example 1

s = "abc"t = "axbzyc"return = true

The characters at indices 0, 2 and 5 of t form abc. Other characters may be skipped.

Example 2

s = "acb"t = "abc"return = false

After matching a and c, no b remains to their right. Having all distinct letters is insufficient.

Example 3

s = "aa"t = "a"return = false

The two occurrences of a in s need two different positions in t.

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 containsOrderedLetters(String s, String t) {
    // Return whether t satisfies the required letter matching.
}
s"abc"
t"axbzyc"
expectedtrue
Checking account…