#K10711. Longest Unique Contiguous Subarray in Range

    ID: 23308 Type: Default 1000ms 256MiB

Longest Unique Contiguous Subarray in Range

Longest Unique Contiguous Subarray in Range

You are given an array of integers and an inclusive range \([l, r]\). Your task is to find the length of the longest contiguous subarray (i.e., a segment of consecutive elements) such that:

  • All elements in this subarray lie within the range \([l, r]\).
  • No element appears more than once in the subarray.

If no valid subarray exists, output 0.

Note: The contiguous subarray is reset when an element outside the given range is encountered.

inputFormat

The input is given via stdin and consists of three lines:

  1. The first line contains an integer \(n\) representing the number of elements in the array.
  2. The second line contains \(n\) space-separated integers representing the array elements. (If \(n = 0\), this line may be empty.)
  3. The third line contains two space-separated integers \(l\) and \(r\) denoting the inclusive range.

outputFormat

Output via stdout a single integer: the length of the longest contiguous subarray that satisfies the conditions.

## sample
10
4 5 2 5 6 2 3 4 1 6
2 5
3