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
4mo

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!
Select
Add answer anonymously...

Cisco Consultant Engineer interview questions & answers

A Consultant Engineer was asked Q. Minimum Cost Path Problem Statement Given an N x M matrix filled with integers, ...read more
A Consultant Engineer was asked Q. Covid Vaccination Distribution Problem As the Government ramps up vaccination dr...read more
A Consultant Engineer was asked Q. Can you describe how a website sends data to a server?

Popular interview questions of Consultant Engineer

A Consultant Engineer was asked Q1. Minimum Cost Path Problem Statement Given an N x M matrix filled with integers, ...read more
A Consultant Engineer was asked Q2. Covid Vaccination Distribution Problem As the Government ramps up vaccination dr...read more
A Consultant Engineer was asked Q3. Can you describe how a website sends data to a server?
Cisco Consultant Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits