Geeksforgeeks

Error

Given an array called **A[]** of sorted integers having no duplicates, find the length of the **L**ongest **A**rithmetic **P**rogression (LLAP) in it.

**Example 1:**

**Input:
**N = 6
set[] = {1, 7, 10, 13, 14, 19}
**Output:** 4
**Explanation:** The longest arithmetic
progression is {1, 7, 13, 19}.

**Example 2:**

**Input:
**N = 5
A[] = {2, 4, 6, 8, 10}
**Output:** 5
**Explanation:** The whole set is in AP.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **lenghtOfLongestAP()** which takes the array of integers called **set[]** and **n **as input parameters and returns the length of LLAP.

**Expected Time Complexity:** O(N^{2})

**Expected Auxiliary Space:** O(N^{2})

**Constraints:**

1 ≤ N ≤ 1000

1 ≤ set[i] ≤ 10^{4}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Longest Arithmetic Progression

...