#C3452. Taco Pattern Formation
Taco Pattern Formation
Taco Pattern Formation
You are given two strings: message
and pattern
. Your task is to determine whether the pattern
can be obtained from message
by deleting some characters without changing the order of the remaining characters.
In other words, check if pattern
is a subsequence of message
. Formally, given two strings \( S \) (message) and \( P \) (pattern), pattern
is a subsequence of message
if there exist indices \( i_1, i_2, \ldots, i_k \) such that \( 1 \leq i_1 < i_2 < \ldots < i_k \leq n \) and \( S[i_1]S[i_2]\ldots S[i_k] = P \). Here, no explicit formula is needed other than the subsequence definition.
If the pattern can be obtained, print YES
; otherwise, print NO
.
inputFormat
The input consists of two lines:
- The first line contains the string
message
. - The second line contains the string
pattern
.
Both strings consist of lowercase letters only.
outputFormat
Output YES
if pattern
can be formed from message
by deleting some characters; otherwise, output NO
.
abpcplea
apple
YES