I have an array, say A = [ 3 5 6 7 ]
. I know I can get the maximum value of this array with max(A)
and it returns 7
, but how can I get the second max (6
) from this array without sorting or removing the first maximum value?
I can propose following tricky solution:
second_max_value = max(A(A~=max(A)))
Here A(A~=max(A))
will be temporary array that not contain maximal value of original array. Than you receive maximum of this array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With