Word Distance - I (soln in cpp)

Given a list of words and two words word1 and word2, return the shortest distance between these two words in the list
Note : You may assume that word1 does not equal to word2, and word1 and word2 are both in the list.
Input Format

First line contains input N. Next line contains N space separated String denoting the elements of the array. third line contains word1 and word2
Constraints

None
Output Format

Shortest Distance between word1 and word 2
Sample Input

5
practice makes perfect coding makes
coding practice

Sample Output

3

Explanation

5
practice makes perfect coding makes
makes coding
output : 1

Hey @Kash-Moulik-3715574511847721

https://hack.codingblocks.com/app/dcb/1599 try to pass all test case

The solution I gave u is O(N^2) see the editorial for O(N) solution

CAN U SEND THAT THE editorial ?

@Kash-Moulik-3715574511847721
Getting 100/100 doesn’t mean anything if u are not solving it urself .
I suggest u to see the editorial in such cases .