#K63827. Longest Contiguous Subarray with Limited Difference

    ID: 31840 Type: Default 1000ms 256MiB

Longest Contiguous Subarray with Limited Difference

Longest Contiguous Subarray with Limited Difference

You are given an array of integers. Your task is to find the length of the longest contiguous subarray such that the difference between the maximum and minimum values in that subarray is at most 1.

Formally, given an integer array A of size n, find the maximum length L such that there exists indices i and j (with 0 ≤ i ≤ j < n) for which:

[ \max_{i \leq k \leq j} A[k] - \min_{i \leq k \leq j} A[k] \leq 1 ]

Your solution should read input from standard input and write the answer to standard output.

inputFormat

The first line contains an integer n (the number of elements in the array). The second line contains n space-separated integers representing the elements of the array.

outputFormat

Output a single integer representing the length of the longest contiguous subarray that satisfies the condition.## sample

1
1
1