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.

bruceewayne | 175 |

manvirag982 | 158 |

Core_Ka_Bachha | 137 |

yash_sharan | 136 |

rajupraaa1234 | 133 |

mr_kksparrow | 433 |

manvirag982 | 374 |

rajupraaa1234 | 268 |

Exception_404 | 254 |

PranathiBhuvanagiri | 242 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.