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
8d

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
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter