We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Functional Programming
  3. Functional Structures
  4. Substring Searching

Substring Searching

Problem
Submissions
Leaderboard
Discussions
  1. Prepare
  2. Functional Programming
  3. Functional Structures
  4. Substring Searching
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions

In 1974, a very fast string searching method was proposed by the name of KMP algorithm with linear run-time complexity. Your task here is to code this (or any similar) algorithm in a functional language.

Given two strings text and pat, find whether pat exists as a substring in text.

Input
First line will contain an integer, T, which represents total number of test cases. Then T test cases follow. Each case will contains two lines each containing a string. First line will contain text while the second line will contain pat.

Output
For each case print YES if pat is a substring of text otherwise NO.

Constraints
1 ≤ T ≤ 10
1 ≤ |pat| ≤ |text| ≤ 100000
All characters in text and pat will be lowercase latin character ('a'-'z').

Sample Input

4
abcdef
def
computer
muter
stringmatchingmat
ingmat
videobox
videobox

Sample Output

YES
NO
YES
YES

Explanation
Test Case #00: Here "def" is present at the end of "abcdef".
Test Case #01: Though "muter" is a subsequence here, but we need it to be asubstring.
Test Case #02: _"ingmat"_ is present at index 3 and 11.
Test Case #03: Both strings are same.

  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy