Word Pattern Problem Statement
Given two strings S
and T
, determine if S
follows the same pattern as T
.
A full match means there is a bijection between a letter of T
and a non-empty word of S
.
Example:
Input:
S = "lion cow cow lion"
T = "wccw"
Output:
Yes
Explanation:
The string S
follows the same pattern as string T
.
Constraints:
1 <= t <= 100
1 <= |S| <= 5000
1 <= |T| <= 5000
- Time Limit: 1 second
Input:
The first line contains an integer 't' denoting the number of test cases.
Each test case consists of two lines:
The first line contains the string 'S'.
The second line contains the string 'T'.
Output:
For each test case, print "Yes" if 'S' follows the same pattern as 'T', otherwise print "No".
Note:
'T' contains only lowercase English letters.
'S' contains only lowercase English letters and spaces.
'S' does not contain any trailing or leading spaces, and all words in 'S' are separated by a single space.

AnswerBot
4mo
Check if two strings follow the same pattern based on bijection between letters and words.
Iterate through each letter in T and corresponding word in S to create a mapping.
Use a hashmap to store the ma...read more
Help your peers!
Add answer anonymously...
MasterCard Full Stack Engineer interview questions & answers
A Full Stack Engineer was asked Q. Next Greater Node in Linked List Problem Statement In a set of linked ninja vill...read more
A Full Stack Engineer was asked Q. Word Pattern Problem Statement Given two strings S and T, determine if S follows...read more
A Full Stack Engineer was asked Q. Longest Palindromic Subsequence Problem Statement Given a string A consisting of...read more
Popular interview questions of Full Stack Engineer
A Full Stack Engineer was asked Q1. Next Greater Node in Linked List Problem Statement In a set of linked ninja vill...read more
A Full Stack Engineer was asked Q2. Word Pattern Problem Statement Given two strings S and T, determine if S follows...read more
A Full Stack Engineer was asked Q3. Longest Palindromic Subsequence Problem Statement Given a string A consisting of...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

