Jai and Veeru ki dosti

4.1

12 votes
Hashing, Medium
Problem

Jai and Veeru are best friends and are very fond of solving different problems. One day Jai decided to challenge Veeru by giving him a programming problem . Jai gives Veeru a pattern (P) and a long string (S) and asks Veeru to find whether there exists any permutation of the pattern (P) in the string (S).

Input: First line contains number of test cases T.Each test case contains two lines ,first line contains pattern (P) and next line contains a text string(S). All characters in both the strings are in lowercase only [a-z].

Output: For each test case print "YES" or "NO" (quotes for clarity) depending on whether any permutation of the pattern(P) exists in the text string(S).

Constraints: 1 ≤ T ≤ 100, 1 ≤ |P| ≤ 1000, 1 ≤ |S| ≤ 100000.

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?