Queries to check if count of increasing and decreasing subarrays is same in given range | Function to check if given range have equal number of increasing as well as decreasing subarrays ; Traverse each query ; For 0 - based indexing ; Condition for same count of increasing & decreasing subarray ; Driver Code
function checkCount ( A , Q , q ) { for ( let i = 0 ; i < q ; i ++ ) { let L = Q [ i ] [ 0 ] ; let R = Q [ i ] [ 1 ] ; L -- ; R -- ; if ( ( A [ L ] < A [ L + 1 ] ) != ( A [ R - 1 ] < A [ R ] ) ) { document . write ( " " + " " ) ; } else { document . write ( " " + " " ) ; } } } let arr = [ 11 , 13 , 12 , 14 ] ; let Q = [ [ 1 , 4 ] , [ 2 , 4 ] ] ; let q = Q . length ; checkCount ( arr , Q , q ) ;