hi, let Avik connect you.


** You can give your thought about this content and request modifications if needed from Ask For Modifications page. Thank You.

** You can check all the posts on the Posts page.

** More about me in the About Me section.

Maximum Difference


  • Approach:

    1. Find the maximum and minimum elements from the given array.

    2. Calculate the difference between the maximum and minimum elements.

    3. Return "ODD" if the difference is ODD, "EVEN" otherwise.


  • Time and Space Complexity:

      • Time Complexity: O(N)

      • Space Complexity: O(1)


Code [C++]

#include <bits/stdc++.h>

string maximumDifference(int n, vector<int>& arr)

{

int maxVal = *max_element(arr.begin(), arr.end());

int minVal = *min_element(arr.begin(), arr.end());

int diff = maxVal - minVal;

return (diff & 1) ? "ODD": "EVEN";

}