Second Max Number
Objective
Given an array, we have to find the second max element of an array
Sample Input
[32,5,26,78,33,1]
Sample Output
33
Code
Here's my solution with the embedded comments.
arr=[32,5,26,78,33,1]
arr.sort(function(a,b){
  return a-b
})
len=arr.length
console.log(arr[len-2]) 
I hope you found this helpful.
Cheers :)

No comments:
Post a Comment