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
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Interview Preparation Kit
  3. Dictionaries and Hashmaps
  4. Two Strings

Two Strings

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics
HackerRank Logo
|
  1. Prepare
  2. Interview Preparation Kit
  3. Dictionaries and Hashmaps
  4. Two Strings
Exit Full Screen View
  • Problem
  • Submissions
  • Leaderboard
  • Discussions
  • Editorial
  • Topics

Given two strings, determine if they share a common substring. A substring may be as small as one character.

Example

These share the common substring .


These do not share a substring.

Function Description

Complete the function twoStrings in the editor below.

twoStrings has the following parameter(s):

  • string s1: a string
  • string s2: another string

Returns

  • string: either YES or NO

Input Format

The first line contains a single integer , the number of test cases.

The following pairs of lines are as follows:

  • The first line contains string .
  • The second line contains string .

Constraints

  • and consist of characters in the range ascii[a-z].

Output Format

For each pair of strings, return YES or NO.

Sample Input

2
hello
world
hi
world

Sample Output

YES
NO

Explanation

We have pairs to check:

  1. , . The substrings and are common to both strings.
  2. , . and share no common substrings.
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website