DEBUGMAX - Editorial

PROBLEM LINK:

Practice
Contest

Author: Pratik
Tester: Khushi
Editorialist: Pratik

DIFFICULTY:

CAKEWALK.

PREREQUISITES:

Arrays.

PROBLEM:

Maximise the difference between any two elements of an array.

(i.e maximum possible difference between any two element of array)

EXPLANATION:

basically you will have to sort given array in increasing order then have to
print last index element minus first index element i.e s[n]-s[0] .

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
#define GCOEN_AADHYAY main
int GCOEN_AADHYAY()
{
int n;
cin >> n;
vectorvect;
for(int i=0;i<=n;i++)
{
int a;
cin >> a;
vect.push_back(a);
}
sort(vect.begin(),vect.end());
cout << abs(vect[0]-vect[n]) << “\n”;
return 0;
}

Tester's Solution

N = int(input())
lst = list(map(int,input().strip().split()))
print(max(lst)-min(lst))

Editorialist's Solution

import java.util.;
import java.lang.
;
import java.io.;
/
Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
Vector v = new Vector(N);
for(int i=0;i<N;i++){
v.add(sc.nextInt());
}
Collections.sort(v);
System.out.println(v.get(v.size()-1) - v.get(0));
}
}