#K80422. String Transformation by Front Insertion
String Transformation by Front Insertion
String Transformation by Front Insertion
You are given two strings source and target. You can repeatedly move any character from any position in the source string to the front. Formally, an operation can be described as follows: if the string is represented as \(s = s_1 s_2 \ldots s_n\), then choosing an index \(i\) (\(1 \leq i \leq n\)) transforms the string to \(s_i s_1 s_2 \ldots s_{i-1} s_{i+1} \ldots s_n\).
Your task is to determine if it is possible to transform source into target using this operation any number of times. Note that the transformation is only possible if both strings have exactly the same multiset of characters.
inputFormat
The input consists of two lines. The first line contains the source string, and the second line contains the target string.
outputFormat
Output a single line containing either YES
if the transformation is possible, or NO
otherwise.
abc
cab
YES