 Timer is Running

Longest Equal Prefix
##### Submissions: 579   Accuracy: 32.63%   Difficulty: Basic   Marks: 1

Given two positive integers x and y, and an array arr[] of positive integers. We need to find the longest prefix index which contains an equal number of x and y. Print the maximum index of largest prefix if exist otherwise print -1.

Input:
The first line of input contains an integer T denoting the number of test cases. Each test case contains three integers n, x, and y where n denotes the number of elements in the array a[]. Next line contains space separated n elements in the array a[].

Output:
Print an integer which denotes the required prefix (0 based indexing).

Constraints:
1<=T<=50
1<=n<=1000
1<=a[i]<=100
1<=x,y<=100

Example:
Input:

2
11 7 42
7 42 5 6 42 8 7 5 3 6 7
5 2 3
2 2 3 3 1

Output:
9
4

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

Contributor: Shashwat Jain
Author: shashwat jain

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.