Check the given conditions
if ( i > 0 && i + 1 < N ) { if ( temp [ i ] < temp [ i + 1 ] && temp [ i ] < temp [ i - 1 ] ) { ct ++ ; } } } document . write ( " " + ct + " " ) ; document . write ( " " ) ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( temp [ i ] + " " ) ; } }