Leaderboard
Showing:
Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5642
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4610
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Complete Leaderboard
Check Arithmetic Progression
Basic Accuracy: 61.97% Submissions: 687 Points: 1

Given an array of N integers. Write a program to check whether an arithmetic progression can be formed using all the given elements. 
 

Example 1:

Input:
N=4
arr[] = { 0,12,4,8 }
Output: YES
Explanation: Rearrange given array as
{0, 4, 8, 12}  which forms an
arithmetic progression.

Example 2:

Input:
N=4
arr[] = {12, 40, 11, 20}
Output: NO

 

Your Task:
Since, this is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function checkIsAP() that takes array arr and integer N as parameters and return true for "Yes" and false for "No".

 

Expected Time Complexity: O(NLogN).
Expected Auxiliary Space: O(1).

 

Constraints:
2 ≤ N ≤ 105

 

to report an issue on this page.

Editorial

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

Yes

All Submissions

My Submissions:

Login to access your submissions.

Check Arithmetic Progression

Output Window