Problems > Longest Arithmetic Stretch

Longest Arithmetic Stretch

Difficulty: 1200 3000 ms 128 MB

implementation

Find the longest CONTIGUOUS stretch that forms an arithmetic progression (constant difference).

Input: the first line has N; the second line has N integers.

Output: the maximum AP stretch length (any 1 or 2 elements always qualify).

Constraints:

  • 1 ≤ N ≤ 105
  • |ai| ≤ 109

Sample Tests

Input 1
7
3 5 7 9 2 4 6
Output 1
4
Input 2
2
1 9
Output 2
2

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.