Skip to content
Advertisement

Calculating the difference between max of even numbers and min of odd numbers of an array

The question statement says – You are given an array of integers A of size N. Return the difference between the maximum among all even numbers of A and the minimum among all odd numbers in A.

Examples – A = [5, 17, 100, 1] – Ans => 100-1 = 99

My Approach –

JavaScript

The code is working fine for all input values other than negatives and I don’t know why? Can somebody help me?

Advertisement

Answer

You can write code like this. I change a little your code.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement