X

DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Count of AP Subsequences
Medium Accuracy: 24.33% Submissions: 272 Points: 4

Given an array A of N positive integers. The task is to count the number of Arithmetic Progression subsequence in the array.

Note: Empty sequence or single element sequence is Arithmetic Progression.

Example 1:

Input :
N = 3
A[] = { 1, 2, 3 }
Output :
8
Explanation:
Arithmetic Progression subsequence from the
given array are: {}, { 1 }, { 2 }, { 3 }, { 1, 2 },
{ 2, 3 }, { 1, 3 }, { 1, 2, 3 }.


Example 2:

Input :
N = 3
A[] = { 10, 20, 30,}
Output :
8
Explanation:
Arithmetic Progression subsequence
from the given array are: {}, { 10 },
{ 20 }, { 30 }, { 10, 20 }, { 20, 30 },
{ 10, 30 }, { 10, 20, 30 }.

You don't need to read input or print anything. Your task is to complete the function count() which takes an integer N and an array A as input parameters and returns the total count of AP sub-sequences in the array.

Expected Time Complexity: O(N * (Minimum value in A - Maximum Value in A))
Expected Space Complexity: O(N)

Constraints:
1<= N <=100
1<= A[i] <=100

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