'Coding has over 700 languages', '67% of programming jobs aren’t in the technology industry', 'Coding is behind almost everything that is powered by electricity'
Topics

# Pattern Matching

Moderate
0/80
Average time to solve is 15m
Contributed by

## Problem statement

You are given a pattern in the form of a string and a collection of words. Your task is to determine if the pattern string and the collection of words have the same order.

Note :
``````The strings are non-empty.

The strings only contain lowercase English letters.
``````
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
``````1 <= T <= 100
1 <= |pattern| <= 5000,
1 <= N <= 5000
1 <= X <= 6

Time Limit: 1sec
``````
Sample Input 1 :
``````1
abab 4
bat ball bat ball
``````
Sample Output 1 :
``````True
``````
Explanation For sample input 1 :
``````In the given example, ‘a’ is present at the 1st and 3rd position, and ‘b’ is present at the 2nd and 4th position. Similarly, in the collection of words, “bat” is present at the 1st and 3rd position while “ball” is present at the 2nd and 4th position. Since the words are following the order of the pattern string, we print “True”.
``````
Sample Input 2 :
``````2
abbb 4
bat ball bat bat
abab 4
bat bat bat bat
``````
Sample Output 2 :
``````False
False
``````
Console