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

9

4

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.

akhyasharma01 | 467 |

ASWATHAMA | 399 |

john_wick | 360 |

mmzeineddine | 295 |

PiyushPandey4 | 271 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

rahulnishad96 | 442 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.