You are given an array **A**, of **N** elements. You need to find minimum distance between given two integers **x** and **y**.

**Distance:** The distance (index-based) between two elements of the array.

**Input Format:**

The first line of input contains an integer **T**, denoting the number of test cases. Then **T** test cases follow. Each test case consists of three lines. The first line of each test case contains an integer **N** denoting size array. Then in the next line are **N** space separated values of the array **A**. The last line of each test case contains two integers** x **and **y**.

**Output Format:**

For each test case, print the required answer .

**Your Task:**

Your task is to complete the function **minDist **which returns an integer denoting the minimum distance between two integers **x and y** in the array. If no such distance is possible then return **-1**.

**Constraints:**

1 <= T <= 100

1 <= N <= 10^{5}

1 <= A, x, y <= 10^{5}

**Example:
Input:**

2

2

1 2

1 2

7

86 39 90 67 84 66 62

42 12

**Output:**

1

-1

**Explanation:
Testcase1: **x = 1 and y = 2. minDistance between x and y is 1.

Author: saksham seth

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.

thanuvinu94 | 425 |

the_coder95 | 380 |

RishabhTanwar1 | 320 |

kunalk02141 | 306 |

RitikRosan | 272 |

the_coder95 | 1226 |

RishabhTanwar1 | 1040 |

tathagat289 | 636 |

thanuvinu94 | 634 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4885 |

Quandray | 4547 |

Login to report an issue on this page.