Permutation in String

Practice this coding question on Coding Gurukul.

Problem statement

A security scanner receives a short code and a longer transmission. It looks for any consecutive block whose letters can be rearranged into the code, because the code's internal letter order may have been scrambled. Your task Return true if s2 contains a contiguous substring that is a permutation of s1. Otherwise return false. Important details The substring must have exactly the same length and character frequencies as s1. Repeated letters matter. The characters cannot be collected from separated positions, and a longer s1 cannot fit inside a shorter s2. Worked example For s1 = ab and s2 = eidbaooo, the block ba has one a and one b. It is a permutation of ab, so the answer is true.

Input format

Two lines: s1 followed by s2.

Output format

Print true if the condition holds, otherwise false.

Constraints

1 <= lengths <= 10000; lowercase English letters.

Sample input

ab
eidbaooo

Sample output

true

Sign in to run or submit a solution in C++, Java or Python.