Queries to check if count of increasing and decreasing subarrays is same in given range | Java program for the above approach ; 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
import java . io . * ; import java . util . * ; class GFG { static void checkCount ( int A [ ] , int Q [ ] [ ] , int q ) { for ( int i = 0 ; i < q ; i ++ ) { int L = Q [ i ] [ 0 ] ; int R = Q [ i ] [ 1 ] ; L -- ; R -- ; if ( ( A [ L ] < A [ L + 1 ] ) != ( A [ R - 1 ] < A [ R ] ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 11 , 13 , 12 , 14 } ; int Q [ ] [ ] = { { 1 , 4 } , { 2 , 4 } } ; int q = Q . length ; checkCount ( arr , Q , q ) ; } }