Hackerank Challenges: Two Strings

Samuel Ezedi
2 min readJan 20, 2021

--

Hello friends, if you found this article then you must be looking for something, today we will be solving a problem I found on Hackerank, and I encourage you to please look at the problem before prying into the solution. Without much Ado, let’s get started.

Problem

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

Example

s1 = 'and'
s2 = 'art'
These share the common substring a.s1 = 'be'
s2 = 'cat'
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 interger p, the number of test cases.
The following p pairs of lines are as follows:
* The first line contains string s1.
* The second line contains string s2.

Output Format

For each pairs of strings, return YES or NO

Sample Input

2
hello
world
hi
world

Sample Output

YES
NO

Explanation

We have p=2 pairs to check:1. s1 = "hello", s2 = "world". The substrings "0" and "1" are common to both strings.2. a = "hi", b = "world". s1 and s2 share no common substrings.

Solution in JS

Solution in Dart

Thanks for your time. Please take time to review the problem before looking at the solution. Remember this is for educational purposes and nothing more. Also, you can follow me here on Linkedin and, on Twitter.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Samuel Ezedi
Samuel Ezedi

No responses yet

Write a response