#C8196. Can Form Subsequence?
Can Form Subsequence?
Can Form Subsequence?
Given two strings s1 and s2, determine whether it is possible to form s2 by selecting some characters from s1 and rearranging them. In other words, for every character in s2, s1 must contain at least as many occurrences of that character. This problem tests your understanding of string manipulation and frequency counting.
Note: Both strings may be empty. If s2 is empty, the answer is always "YES". Otherwise, if any character in s2 appears more times than it does in s1, the answer is "NO".
The condition can be expressed mathematically as follows, using LaTeX notation:
$$\text{For all } c,\; \text{count}_{s2}(c) \leq \text{count}_{s1}(c) $$inputFormat
The input consists of two lines. The first line contains the string s1, and the second line contains the string s2. Both strings may include any characters.
outputFormat
Output a single line containing YES
if s2 can be formed by rearranging some characters from s1, or NO
otherwise.
bacebfg
abb
YES