βœ…Absolute value discrepancy (Contest)

Absolute value discrepancy easy Time Limit: 2 sec Memory Limit: 128000 kB

Problem Statement :

You are given an array A of size N. For all pairs (i, j) (1 <= i < j <= N), find the maximum value of abs(Ai - Aj) in the array. Input The first line of the input contains a single integer N. The second line of the input contains N space seperated integers.

Constraints: 2 <= N <= 105 1 <= Ai <= 109 Output Print the maximum value of abs(Ai - Aj) in the array. Example Sample Input: 5 7 9 4 1 8

Sample Output: 8

link: https://my.newtonschool.co/playground/code/eiih4plvhtr0/


#include <bits/stdc++.h> // header file includes every Standard library
using namespace std;
#define int long long


signed main(){
    int n;
    cin >> 
    vector<int>a(n);
    for(auto &i : a) cin>>i;
    sort(a.begin(),a.end());
    cout<<a[n-1] - a[0];
}

Last updated