#K39142. Scrambled String Verification
Scrambled String Verification
Scrambled String Verification
You are given two strings s1 and s2. Your task is to determine whether s2 is a scrambled version of s1.
In this problem, a string s2 is considered a scrambled version of s1 if and only if:
$$|s1| = |s2| \quad \text{and} \quad \text{sort}(s1) = \text{sort}(s2) $$In other words, the two strings must have the same length and consist of the same characters with the same frequencies. For example, "listen" and "silent" are scrambled versions of each other, whereas "apple" and "pale" are not.
The input is provided via stdin and the output should be printed to stdout.
inputFormat
The input consists of two lines:
- The first line contains the string s1.
- The second line contains the string s2.
Both strings will contain only printable characters without extra spaces.
outputFormat
Output a single line with either True
or False
(without quotes) indicating whether s2 is a scrambled version of s1.
listen
silent
True