Number of non | Java implementation of the approach ; Function to return the count of increasing subarrays of length k ; To store the final result ; Two pointer loop ; Initialising j ; Looping till the subarray increases ; Updating the required count ; Updating i ; Returning res ; Driver code
class GFG { static int cntSubArrays ( int [ ] arr , int n , int k ) { int res = 0 ; int i = 0 ; while ( i < n ) { int j = i + 1 ; while ( j < n && arr [ j ] >= arr [ j - 1 ] ) j ++ ; res += Math . max ( j - i - k + 1 , 0 ) ; i = j ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 2 , 5 } ; int n = arr . length ; int k = 2 ; System . out . println ( cntSubArrays ( arr , n , k ) ) ; } }