Check Ordered Letter Containment
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) → booleanExamples
Example 1
s = "abc"t = "axbzyc"return = trueThe characters at indices 0, 2 and 5 of t form abc. Other characters may be skipped.
Example 2
s = "acb"t = "abc"return = falseAfter matching a and c, no b remains to their right. Having all distinct letters is insufficient.
Example 3
s = "aa"t = "a"return = falseThe 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
athroughz.