Timer is Running

Closest Strings
Submissions: 3226   Accuracy:


  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.



1<=size of strings of array<=100

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




the quick brown fox quick

fox the



Expected time complexity


** 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.