Pattern Search in Strings

Given two strings S and P consisting of lowercase English alphabets, determine if P is present in S as a substring.

Input:

The first line contains an integer T, the number of test cases.
Each test case consists of a single line with two space-separated strings P and S.

Output:

For each test case, output "YES" if P is a substring of S, otherwise output "NO".

Example:

Input:
3
abc abcdef
xyz abcdef
def abcdef
Output:
YES
NO
YES

Constraints:

  • 1 <= T <= 100
  • 1 <= |S| <= 10000
  • 1 <= |P| < |S|

Note:

You are not required to print anything; the output is managed by the system. Implement the function to return the correct result.
AnswerBot
5d

The task is to determine if a given substring is present in a given string.

  • Iterate through the string S and check if each substring of length equal to the length of P matches P.

  • Use string comparison t...read more

Help your peers!
Add answer anonymously...
Cisco Consultant 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