Closest Strings
Submissions: 2713   Accuracy:

26.71%

  Difficulty: Easy   Marks: 2

You are given a array of string followed by two words. You have to find the minimum distance between the two words in the given array of string

 For example:
(“the”, “quick”, “brown”, “fox”, “quick”)
distance(“fox”,”the”) = 3
distance(“quick”, “fox”) = 1

Input:The first line consists of  a integer T denoting the number of test cases .Each test case consists of three lines .First line consists of an integer N denoting the size of array of strings .Second line consists of N spaced strings made of 'a' to 'z' .Third line consists of two spaced strings s1,s2 for which you have two find minimum distance.


Output:The output consists of a single line for each testcase which is the minimum distance between the two given strings.
Constraints:

1<=T<=1000

1<=N<=100

1<=size of strings of array<=100

It is given that s1 and s2 will always be present in the array
Example:

Input:

1

5

the quick brown fox quick

fox the

Output:

3

Expected time complexity

O(n)

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Ayush Jha
Author: Ayush jha


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.