Dodomeki
Sign in

130. An Ordered Mix

Medium

Given the strings texto1, texto2, and resultado, determine whether resultado can be formed by using every character from texto1 and texto2 exactly once. The relative order of the characters from each original string must be preserved in resultado.

Return true if this is possible, and false otherwise.

Example 1
Input: texto1 = "ab", texto2 = "cd", resultado = "acbd"
Output: true
Explanation: The characters from each string appear in their original order.
Example 2
Input: texto1 = "ab", texto2 = "cd", resultado = "adbc"
Output: false
Explanation: To use `d` before `b`, `c` would have to appear before `d`, which does not happen.
Example 3
Input: texto1 = "ab", texto2 = "cd", resultado = "adcb"
Output: false
Explanation: The order of the characters from `texto2` is reversed.
Constraints
  • 0 <= texto1.length, texto2.length <= 1000
  • `texto1`, `texto2`, and `resultado` contain only lowercase English letters.
Dynamic programmingStrings
Caso 1
texto1 =
"ab"
texto2 =
"cd"
resultado =
"acbd"
Expected =
true
Caso 2
texto1 =
"ab"
texto2 =
"cd"
resultado =
"adbc"
Expected =
false
Caso 3
texto1 =
"ab"
texto2 =
"cd"
resultado =
"adcb"
Expected =
false

Run checks these 3 cases. Submit runs all 12, including hidden ones.