Check if a graph constructed from an array based on given conditions consists of a cycle or not | Function to check if the graph constructed from given array contains a cycle or not ; Traverse the array ; If arr [ i ] is less than arr [ i - 1 ] and arr [ i ] ; Given array ; Size of the array
function isCycleExists ( arr , N ) { for ( let i = 1 ; i < N ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] && arr [ i ] < arr [ i + 1 ] ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } let arr = [ 1 , 3 , 2 , 4 , 5 ] ; let N = arr . length ; isCycleExists ( arr , N ) ;