Skip to content

Practice Check if an Original String Exists Given Two Encoded Strings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#2060
LeetCode Problem

Check if an Original String Exists Given Two Encoded Strings

Problem Statement

A lowercase string may be encoded by splitting it into nonempty consecutive parts, replacing any selection of parts with their decimal lengths, and concatenating all parts. Given encoded strings s1 and s2 containing lowercase letters and digits 1 through 9, return whether some original string could produce both encodings. A run of digits may come from several neighboring replaced parts. Neither input has more than three consecutive digits.

Source: Check if an Original String Exists Given Two Encoded Strings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s1 = "internationalization", s2 = "i18n"
Output
true

# Example 2

Input
s1 = "l123e", s2 = "44"
Output
true

# Example 3

Input
s1 = "a5b", s2 = "c5b"
Output
false

Constraints

1 <= s1.length, s2.length <= 40
s1 and s2 consist of digits 1-9 (inclusive), and lowercase English letters only.
The number of consecutive digits in s1 and s2 does not exceed 3.

Related LeetCode Problems

Practice more problems similar to Check if an Original String Exists Given Two Encoded Strings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.