#K71502. Is Subsequence
Is Subsequence
Is Subsequence
Given two strings S and P, determine whether P is a subsequence of S. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
In other words, if P is a subsequence of S, then all characters of P must appear in S in the same order as they appear in P, though not necessarily consecutively. Formally, if we denote the length of P as \(m\) and the length of S as \(n\), then there exists a sequence of indices \(0 \leq i_1 < i_2 < \cdots < i_m < n\) such that \(S[i_j] = P[j-1]\) for every \(1 \leq j \leq m\).
inputFormat
The input consists of two lines:
- The first line contains the string S.
- The second line contains the string P.
outputFormat
Output a single line with either True
or False
indicating whether P is a subsequence of S.
codingassessment
cat
True