312. Equal Counts of Two Values
Given an array and two values x and y, print the length of the longest
contiguous stretch containing exactly as many x as y.
Values that are neither x nor y do not affect the balance and may sit
inside the stretch freely, so 1 3 2 with x = 1 and y = 2 has an answer
of 3.
This is problem 299 generalised. Score x as +1, y as -1 and
everything else as 0, then a balanced stretch is one where the running total
is unchanged, which is a repeated prefix sum again.
Constraints - `1 ≤ n ≤ 200000` - `-1000000000 ≤ values, x, y ≤ 1000000000` - `x != y`
Input
The first line contains three integers n, x and y.
The second line contains n integers.
Output
Print one integer, the length of the longest balanced stretch, or 0 if there is none.
Hints
Four rungs, in order. The last two open once you have submitted an attempt — a wrong one counts.