Function to return the largest element such that its previous and next element product is maximum
function maxElement ( a , n ) { if ( n < 3 ) return - 1 ; let maxElement = a [ 0 ] ; let maxProd = a [ n - 1 ] * a [ 1 ] ; for ( let i = 1 ; i < n ; i ++ ) {