Skip to main content
Back to problems
Codeforces
Medium
Strings
Hash Maps
Suffix Structures

Determine whether one string can be formed from another by deleting characters, and report the relationship between the two strings.

Acceptance 0%
Problem Statement

Problem Summary

You are given two strings. Your task is to determine whether the first string can be obtained from the second string by removing some characters without changing the order of the remaining characters.

If the first string is obtainable, you should also determine whether the first string is a proper suffix-structure of the second string in the sense that the second string contains it as a subsequence and has extra characters.

This is a classic string-processing task where you compare characters in order and track how much of the target string has been matched.

Notes

  • Characters must remain in order.
  • You may skip any number of characters in the source string.
  • The two strings are not required to have the same length.

Input Format

The input format is not guaranteed from the provided metadata. For practice purposes, assume:

  • A line containing string s
  • A line containing string t

where the task is to check whether s can be formed from t by deleting characters from t while preserving order.

Output Format

Print the required yes/no decision for the string relationship described in the problem statement. If multiple conditions are part of the task, print the corresponding classification requested by the statement.

Constraints

  • Strings contain lowercase Latin letters unless otherwise specified.
  • Lengths are small to moderate, suitable for linear scanning.
  • Use an O(s+t)O(|s| + |t|) approach if checking subsequence compatibility.
Examples
Sample cases returned by the problem API.

Example 1

Input

abc
a1b2c3

Output

YES

Explanation

The string abc appears in order inside a1b2c3 if we delete the digits.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.