Find a triplet ( i , j , k ) from an array such that i < j < k and arr [ i ] < arr [ j ] > arr [ k ] | Function to find a triplet such that i < j < k and arr [ i ] < arr [ j ] and arr [ j ] > arr [ k ] ; Traverse the array ; Condition to satisfy for the resultant triplet ; Otherwise , triplet doesn 't exist ; Driver Code
function print_triplet ( arr , n ) { for ( var i = 1 ; i <= n - 2 ; i ++ ) { if ( arr [ i - 1 ] < arr [ i ] && arr [ i ] > arr [ i + 1 ] ) { document . write ( i - 1 + " " + i + " " + ( i + 1 ) ) ; return ; } } document . write ( - 1 ) ; } var arr = [ 4 , 3 , 5 , 2 , 1 , 6 ] ; var N = arr . length ; print_triplet ( arr , N ) ;