Last Updated: 16 Mar, 2021

Maximum Difference

Easy
Asked in companies
PayPalOlaRaja Software Labs (RSL)

Problem statement

You are given an array 'ARR' of the 'N' element. Your task is to find the maximum difference between any of the two elements from 'ARR'.

If the maximum difference is even print “EVEN” without quotes. If the maximum difference is odd print “ODD” without quotes.

For example:

Given 'ARR' = [1, 10, 5, 2, 8, 1 ] , answer is "ODD".
Here the maximum difference is between 10 and 1, 10 - 1 = 9
Input Format:
The first line of input contains an integer T’ denoting the number of test cases to run. Then the test case follows.

The first line of each test case contains ‘N’, the length of the array 'ARR'.

The second line of each test case contains ‘N’ space-separated elements of 'ARR'.
Output Format:
For each test case, print a single line containing “ODD” without quotes if the maximum difference is odd else print “EVEN” without quotes.

The output for each test case is printed in a separate line.
Note:
You don’t need to print anything. It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 100
1 <= N <= 5000 
1 <= ARR[i] <= 10 ^ 9

where ‘N’ is the length of the array 'ARR', and 'ARR[i]' is an element of the 'ARR' respectively.

Time limit: 1 sec.

Approaches

01 Approach

We will iterate over ARR and find the MAX and MIN of the ARR. And if the MAX - MIN is odd the return “ODD” else return "EVEN". 

The algorithm will be-

  1. MAX = -1, MIN= 10 ^ 9 + 1
  2. For VAL in ARR.
    1. If MAX < VAL
      1. MAX = VAL
    2. If MIN > VAL
      1. MIN = VAL
  3. IF (MAX-MIN) % 2
    1. Return ODD
  4. ELSE
    1. Return EVEN