codeparrot/xlcost-text-to-code huggingface dataset:
Maximum sum of K | Java Program to implement the above approach ; Function to print the sum of subarray of length K having maximum distinct prime factors ; If K exceeds N ; Stores the count of distinct primes ; True , if index ' i ' is a prime ; Initialize the count of factors to 0 and set all indices as prime ; If i is prime ; Number is prime ; Count of factors of a prime number is 1 ; Increment CountDistinct as the factors of i ; Mark its multiple non - prime ; Compute sum of first K - length subarray ; Compute sums of remaining windows by removing first element of the previous window and adding last element of the current window ; Print the maximum sum ; Driver Code ; Given array ; Given size of subarray ; Size of the array
import java . io . * ; import java . util . * ; class GFG { static int MAX = 100001 ; static void maxSum ( int arr [ ] , int N , int K ) { if ( N < K ) { System . out . println ( " Invalid " ) ; return ; } int CountDistinct [ ] = new int [ MAX + 1 ] ; boolean prime [ ] = new boolean [ MAX + 1 ] ; for ( int i = 0 ; i <= MAX ; i ++ ) { CountDistinct [ i ] = 0 ; prime [ i ] = true ; } for ( int i = 2 ; i <= MAX ; i ++ ) { if ( prime [ i ] == true ) { CountDistinct [ i ] = 1 ; for ( int j = i * 2 ; j <= MAX ; j += i ) { CountDistinct [ j ] ++ ; prime [ j ] = false ; } } } int Maxarr_sum = 0 , DistPrimeSum = 0 ; for ( int i = 0 ; i < K ; i ++ ) { Maxarr_sum += arr [ i ] ; DistPrimeSum += CountDistinct [ arr [ i ] ] ; } int curr_sum = DistPrimeSum ; int curr_arrSum = Maxarr_sum ; for ( int i = K ; i < N ; i ++ ) { curr_sum += CountDistinct [ arr [ i ] ] - CountDistinct [ arr [ i - K ] ] ; curr_arrSum += arr [ i ] - arr [ i - K ] ; if ( curr_sum > DistPrimeSum ) { DistPrimeSum = curr_sum ; Maxarr_sum = curr_arrSum ; } else if ( curr_sum == DistPrimeSum ) { Maxarr_sum = Math . max ( curr_arrSum , Maxarr_sum ) ; } } System . out . println ( Maxarr_sum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 2 , 10 , 3 } ; int K = 3 ; int N = arr . length ; maxSum ( arr , N , K ) ; } }
Count Pronic numbers from a given range | Java program to implement the above approach ; Function to check if x is a Pronic Number or not ; Check for Pronic Number by multiplying consecutive numbers ; Function to count pronic numbers in the range [ A , B ] ; Initialise count ; Iterate from A to B ; If i is pronic ; Increment count ; Print count ; Driver Code ; Function call to count pronic numbers in the range [ A , B ]
import java . util . * ; class GFG { static boolean checkPronic ( int x ) { for ( int i = 0 ; i <= ( int ) ( Math . sqrt ( x ) ) ; i ++ ) { if ( ( x == i * ( i + 1 ) ) != false ) { return true ; } } return false ; } static void countPronic ( int A , int B ) { int count = 0 ; for ( int i = A ; i <= B ; i ++ ) { if ( checkPronic ( i ) != false ) { count ++ ; } } System . out . print ( count ) ; } public static void main ( String args [ ] ) { int A = 3 , B = 20 ; countPronic ( A , B ) ; } }
Count Pronic numbers from a given range | Java program for the above approach ; Function to count pronic numbers in the range [ A , B ] ; Check upto sqrt N ; If product of consecutive numbers are less than equal to num ; Return N - 1 ; Function to count pronic numbers in the range [ A , B ] ; Subtract the count of pronic numbers which are <= ( A - 1 ) from the count f pronic numbers which are <= B ; Driver Code ; Function call to count pronic numbers in the range [ A , B ]
import java . util . * ; class GFG { static int pronic ( int num ) { int N = ( int ) Math . sqrt ( num ) ; if ( N * ( N + 1 ) <= num ) { return N ; } return N - 1 ; } static int countPronic ( int A , int B ) { return pronic ( B ) - pronic ( A - 1 ) ; } public static void main ( String [ ] args ) { int A = 3 ; int B = 20 ; System . out . print ( countPronic ( A , B ) ) ; } }
Count integers from a given range with no odd divisors | Java program to implement the above approach ; Function to count integers in the range 1 to N having no odd divisors ; Traverse the array ; Stores the nearest power of two less than arr [ i ] ; Stores the count of integers with no odd divisor for each query ; Iterate until powerOfTwo is less then or equal to arr [ i ] ; Print the answer for the current element ; Driver Code ; Given array ; Size of the array
import java . util . * ; class GFG { static void oddDivisors ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int powerOfTwo = 2 ; int count = 0 ; while ( powerOfTwo <= arr [ i ] ) { count ++ ; powerOfTwo = 2 * powerOfTwo ; } System . out . print ( count + " ▁ " ) ; } return ; } public static void main ( String args [ ] ) { int arr [ ] = { 15 , 16 , 20 , 35 } ; int N = arr . length ; oddDivisors ( arr , N ) ; } }
Check if all array elements can be reduced to 0 by repeatedly reducing pairs of consecutive elements by their minimum | Java program to implement the above approach ; Function to check if it is possible to convert the array ; Traverse the array range [ 1 , N - 1 ] ; If arr [ i ] < arr [ i - 1 ] ; Otherwise ; Decrement arr [ i ] by arr [ i - 1 ] ; If arr [ n - 1 ] is not equal to zero ; Otherwise ; Driver Code ; Function Call
import java . util . * ; class GFG { static void checkPossible ( int [ ] arr , int n ) { for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { System . out . print ( "NoNEW_LINE"); return ; } else { arr [ i ] -= arr [ i - 1 ] ; arr [ i - 1 ] = 0 ; } } if ( arr [ n - 1 ] == 0 ) { System . out . print ( "YesNEW_LINE"); } else { System . out . print ( "NoNEW_LINE"); } } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 3 , 3 , 4 , 2 } ; int N = arr . length ; checkPossible ( arr , N ) ; } }
Nearest smaller power of 2 for every digit of a number | Java program to implement the above approach ; Function to find the nearest power of two for every digit of a given number ; Converting number to string ; Traverse the array ; Calculate log base 2 of the current digit s [ i ] ; Highest power of 2 <= s [ i ] ; ASCII conversion ; Driver Code
import java . util . * ; class GFG { static void highestPowerOfTwo ( int num ) { String s = Integer . toString ( num ) ; for ( int i = 0 ; i < ( int ) s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '0' ) { System . out . print ( "0" ) ; continue ; } int lg = ( int ) ( Math . log ( s . charAt ( i ) - '0' ) / Math . log ( 2 ) ) ; int p = ( int ) Math . pow ( 2 , lg ) ; System . out . print ( ( char ) ( p + 48 ) ) ; } } public static void main ( String args [ ] ) { int num = 4317 ; highestPowerOfTwo ( num ) ; } }
Maximum prefix sum after K reversals of a given array | Java program for the above approach ; Function to find the maximum prefix sum after K reversals of the array ; Stores the required sum ; If K is odd , reverse the array ; Store current prefix sum of array ; Traverse the array arr [ ] ; Add arr [ i ] to currsum ; Update maximum prefix sum till now ; Print the answer ; Driver Code ; Function Call
import java . io . * ; import java . util . * ; class GFG { static void maxSumAfterKReverse ( Integer arr [ ] , int K , int N ) { int sum = Integer . MIN_VALUE ; if ( K % 2 != 0 ) Collections . reverse ( Arrays . asList ( arr ) ) ; int currsum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { currsum += arr [ i ] ; sum = Math . max ( sum , currsum ) ; } System . out . print ( sum ) ; } public static void main ( String [ ] args ) { Integer [ ] arr = { 1 , 5 , 8 , 9 , 11 , 2 } ; int K = 1 ; int N = arr . length ; maxSumAfterKReverse ( arr , K , N ) ; } }
Print all submasks of a given mask | Java Program for above approach ; Function to print the submasks of N ; Driver Code
import java . util . * ; class GFG { static void SubMasks ( int N ) { for ( int S = N ; S > 0 ; S = ( S - 1 ) & N ) { System . out . print ( S + " ▁ " ) ; } } public static void main ( String args [ ] ) { int N = 25 ; SubMasks ( N ) ; } }
Count pairs from a given range having equal Bitwise OR and XOR values | Java program for the above approach ; Function to calculate ( x ^ y ) % MOD ; Initialize result ; Update x if it is more than or equal to MOD ; If y is odd , multiply x with result ; y must be even now y = y / 2 ; Return ( x ^ y ) % MOD ; Function to count total pairs ; The upper bound is 2 ^ N ; Stores the count of pairs ; Generate all possible pairs ; Find XOR of both integers ; Find OR of both integers ; If both are equal ; Increment count ; Print count % MOD ; Driver Code ; Function Call
import java . io . * ; class GFG { static int MOD = 1000000007 ; static int power ( int x , int y ) { int res = 1 ; x = x % MOD ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % MOD ; y = y >> 1 ; x = ( x * x ) % MOD ; } return res ; } static void countPairs ( int N ) { int high = power ( 2 , N ) ; int count = 0 ; for ( int i = 0 ; i < high ; i ++ ) { for ( int j = 0 ; j < high ; j ++ ) { int X = ( i ^ j ) ; int Y = ( i j ) ; if ( X == Y ) { count ++ ; } } } System . out . println ( count % MOD ) ; } public static void main ( String [ ] args ) { int N = 10 ; countPairs ( N ) ; } }
Count pairs from a given range having equal Bitwise OR and XOR values | Java program for the above approach ; Function to find the value of ( x ^ y ) % MOD ; Initialize result ; Update x if it is more than or equal to MOD ; If y is odd , multiply x with result ; y must be even now , then update y / 2 ; Return ( x ^ y ) % MOD ; Function to count total pairs ; Finding 3 ^ N % 10 ^ 9 + 7 ; Driver Code ; Function Call
import java . util . * ; class GFG { static final int MOD = 1000000007 ; static int power ( int x , int y ) { int res = 1 ; x = x % MOD ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % MOD ; y = y >> 1 ; x = ( x * x ) % MOD ; } return res ; } static void countPairs ( int N ) { System . out . print ( power ( 3 , N ) ) ; } public static void main ( String [ ] args ) { int N = 10 ; countPairs ( N ) ; } }
Minimize swaps required to place largest and smallest array elements at first and last array indices | Java program for the above approach ; Function to find the minimum count of adjacent swaps to move largest and smallest element at the first and the last index of the array , respectively ; Stores the smallest array element ; Stores the smallest array element ; Stores the last occurrence of the smallest array element ; Stores the first occurrence of the largest array element ; Traverse the array arr [ ] ; If a [ i ] is less than min_element ; Update min_element ; Update min_ind ; If a [ i ] is greater than max_element ; Update max_element ; Update max_ind ; If max_ind is equal to min_ind ; Return 0 ; If max_ind is greater than min_ind ; Otherwise ; Driver Code ; Input ; Print the result
import java . util . * ; class GFG { static int minimumMoves ( int [ ] a , int n ) { int min_element = Integer . MAX_VALUE ; int max_element = Integer . MIN_VALUE ; int min_ind = - 1 ; int max_ind = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] <= min_element ) { min_element = a [ i ] ; min_ind = i ; } if ( a [ i ] > max_element ) { max_element = a [ i ] ; max_ind = i ; } } if ( max_ind == min_ind ) { return 0 ; } else if ( max_ind > min_ind ) { return max_ind + ( n - min_ind - 2 ) ; } else { return max_ind + n - min_ind - 1 ; } } public static void main ( String [ ] args ) { int arr [ ] = { 35 , 46 , 17 , 23 } ; int N = arr . length ; System . out . print ( minimumMoves ( arr , N ) + "NEW_LINE"); } }
Find the index of the smallest element to be removed to make sum of array divisible by K | Java program to implement the above approach ; Function to find index of the smallest array element required to be removed to make sum divisible by K ; Stores sum of array elements ; Stores index of the smallest element removed from the array to make sum divisible by K ; Stores the smallest element removed from the array to make sum divisible by K ; Traverse the array , arr [ ] ; Update sum ; Traverse the array arr [ ] ; Calculate remaining sum ; If sum is divisible by K ; If res == - 1 or mini is greater than arr [ i ] ; Update res and mini ; Driver Code
import java . util . * ; class GFG { static int findIndex ( int arr [ ] , int n , int K ) { int sum = 0 ; int res = - 1 ; int mini = ( int ) 1e9 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { int temp = sum - arr [ i ] ; if ( temp % K == 0 ) { if ( res == - 1 mini > arr [ i ] ) { res = i + 1 ; mini = arr [ i ] ; } } } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 14 , 7 , 8 , 2 , 4 } ; int K = 7 ; int N = arr . length ; System . out . print ( findIndex ( arr , N , K ) ) ; } }
Count subarrays having a single distinct element that can be obtained from a given array | Java program for the above approach ; Function to count subarrays of single distinct element into which given array can be split ; Stores the count ; Stores frequency of array elements ; Traverse the array ; Traverse the map ; Increase count of subarrays by ( frequency - 1 ) ; Driver Code
import java . io . * ; import java . util . * ; class GFG { static void divisionalArrays ( int arr [ ] , int N ) { int sum = N ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } for ( Map . Entry x : mp . entrySet ( ) ) { if ( ( int ) x . getValue ( ) > 1 ) { sum += ( int ) x . getValue ( ) - 1 ; } } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 3 } ; int N = arr . length ; divisionalArrays ( arr , N ) ; } }
Count inversions in a sequence generated by appending given array K times | Java program for the above approach ; Function to count the number of inversions in K copies of given array ; Stores count of inversions in the given array ; Stores the count of pairs of distinct array elements ; Traverse the array ; Generate each pair ; Check for each pair , if the condition is satisfied or not ; If pairs consist of distinct elements ; Count inversiosn in the sequence ; Print the answer ; Driver Code ; Given array ; Given K ; Size of the array
import java . util . * ; class GFG { static void totalInversions ( int arr [ ] , int K , int N ) { int inv = 0 ; int X = 0 ; int i , j ; for ( i = 0 ; i < N ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) { if ( arr [ i ] > arr [ j ] && i < j ) inv ++ ; if ( arr [ i ] > arr [ j ] ) X ++ ; } } int totalInv = X * K * ( K - 1 ) / 2 + inv * K ; System . out . println ( totalInv ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 1 , 3 } ; int K = 3 ; int N = arr . length ; totalInversions ( arr , K , N ) ; } }
Count ways to generate an array having distinct elements at M consecutive indices | Java program for the above approach ; Modular function to calculate factorial ; Stores factorial of N ; Iterate over the range [ 1 , N ] ; Update result ; Function to count ways to replace array elements having 0 s with non - zero elements such that any M consecutive elements are distinct ; Store m consecutive distinct elements such that arr [ i ] is equal to B [ i % M ] ; Stores frequency of array elements ; Traverse the array arr [ ] ; If arr [ i ] is non - zero ; If B [ i % M ] is equal to 0 ; Update B [ i % M ] ; Update frequency of arr [ i ] ; If a duplicate element found in M consecutive elements ; Handling the case of inequality ; Stores count of 0 s in B [ ] ; Traverse the array , B [ ] ; If B [ i ] is 0 ; Update cnt ; Calculate factorial ; Driver Code ; Given M ; Given array ; Size of the array ; Function Call
import java . io . * ; class GFG { static int Fact ( int N ) { int result = 1 ; for ( int i = 1 ; i <= N ; i ++ ) { result = ( result * i ) ; } return result ; } static void numberOfWays ( int M , int [ ] arr , int N ) { int [ ] B = new int [ M ] ; int [ ] counter = new int [ M + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != 0 ) { if ( B [ i % M ] == 0 ) { B [ i % M ] = arr [ i ] ; counter [ arr [ i ] ] ++ ; if ( counter [ arr [ i ] ] > 1 ) { System . out . println ( 0 ) ; return ; } } else if ( B [ i % M ] != arr [ i ] ) { System . out . println ( 0 ) ; return ; } } } int cnt = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( B [ i ] == 0 ) { cnt ++ ; } } System . out . println ( Fact ( cnt ) ) ; } public static void main ( String [ ] args ) { int M = 4 ; int [ ] arr = new int [ ] { 1 , 0 , 3 , 0 , 0 } ; int N = arr . length ; numberOfWays ( M , arr , N ) ; } }
Maximize sum by traversing diagonally from each cell of a given Matrix | Java program for the above approach ; Function to find the maximum sum ; Loop to traverse through the upper triangular matrix and update the maximum sum to ans ; Traverse through the lower triangular matrix ; Driver Code ; Given matrix ; Given dimension
import java . util . * ; class GFG { static int MaximumSum ( int [ ] [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = 0 , y = i , sum = 0 ; for ( int j = i ; j < n ; j ++ ) { sum += arr [ x ++ ] [ y ++ ] ; } if ( sum > ans ) ans = sum ; } for ( int i = 1 ; i < n ; i ++ ) { int x = i , y = 0 , sum = 0 ; for ( int j = i ; j < n ; j ++ ) { sum += arr [ x ++ ] [ y ++ ] ; } if ( sum > ans ) ans = sum ; } return ans ; } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 1 , 2 , 3 } , { 3 , 5 , 10 } , { 1 , 3 , 5 } } ; int n = arr . length ; System . out . print ( MaximumSum ( arr , n ) ) ; } }
Count array elements exceeding all previous elements as well as the next array element | Java program for the above approach ; Function to count array elements satisfying the given condition ; If there is only one array element ; Traverse the array ; Update the maximum element encountered so far ; Count the number of array elements strictly greater than all previous and immediately next elements ; Print the count ; Driver Code ; Given array ; Size of the array
import java . io . * ; class GFG { static void numberOfIntegers ( int [ ] arr , int N ) { int cur_max = 0 , count = 0 ; if ( N == 1 ) { count = 1 ; } else { for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] > cur_max ) { cur_max = arr [ i ] ; if ( arr [ i ] > arr [ i + 1 ] ) { count ++ ; } } } if ( arr [ N - 1 ] > cur_max ) count ++ ; } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int [ ] arr = new int [ ] { 1 , 2 , 0 , 7 , 2 , 0 , 2 , 0 } ; int N = arr . length ; numberOfIntegers ( arr , N ) ; } }
Count ways to represent N as sum of powers of 2 | Java program to implement the above approach ; Base Cases ; Check if 2 ^ k can be used as one of the numbers or not ; Otherwise ; Count number of ways to N using 2 ^ k - 1 ; Driver code
import java . util . * ; class GFG { static int numberOfWays ( int n , int k ) { if ( n == 0 ) return 1 ; if ( k == 0 ) return 1 ; if ( n >= ( int ) Math . pow ( 2 , k ) ) { int curr_val = ( int ) Math . pow ( 2 , k ) ; return numberOfWays ( n - curr_val , k ) + numberOfWays ( n , k - 1 ) ; } else return numberOfWays ( n , k - 1 ) ; } public static void main ( String [ ] args ) { int n = 4 ; int k = ( int ) ( Math . log ( n ) / Math . log ( 2 ) ) ; System . out . println ( numberOfWays ( n , k ) ) ; } }
Count ways to obtain triplets with positive product consisting of at most one negative element | Java Program to implement the above approach ; Function to calculate possible number of triplets ; counting frequency of positive numbers in array ; If current array element is positive ; Increment frequency ; Select a triplet from freq elements such that i < j < k . ; Driver Code
import java . util . * ; class GFG { static int possibleTriplets ( int arr [ ] , int N ) { int freq = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] > 0 ) { freq ++ ; } } return ( int ) ( ( freq * 1L * ( freq - 1 ) * ( freq - 2 ) ) / 6 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 5 , - 9 , - 3 , 6 } ; int N = arr . length ; System . out . print ( possibleTriplets ( arr , N ) ) ; } }
Maximize difference between sum of even and odd | Java program to implement the above approach ; Function to find the maximum possible difference between sum of even and odd indices ; Convert arr [ ] into 1 - based indexing ; Reverse the array ; Convert arr [ ] into 1 based index ; Reverse the array ; Stores maximum difference between sum of even and odd indexed elements ; Traverse the array ; If arr . get ( i ) is local maxima ; Update maxDiff ; If arr . get ( i ) is local minima ; Update maxDiff ; Driver Code ; Size of array ; Function Call
import java . util . * ; class GFG { static void maxPossibleDiff ( Vector < Integer > arr , int N ) { arr . add ( - 1 ) ; Collections . reverse ( arr ) ; arr . add ( - 1 ) ; Collections . reverse ( arr ) ; int maxDiff = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( arr . get ( i ) > arr . get ( i - 1 ) && arr . get ( i ) > arr . get ( i + 1 ) ) { maxDiff += arr . get ( i ) ; } if ( arr . get ( i ) < arr . get ( i - 1 ) && arr . get ( i ) < arr . get ( i + 1 ) ) { maxDiff -= arr . get ( i ) ; } } System . out . print ( maxDiff ) ; } public static void main ( String [ ] args ) { int [ ] array = { 3 , 2 , 1 , 4 , 5 , 2 , 1 , 7 , 8 , 9 } ; Vector < Integer > v = new Vector < > ( ) ; for ( int i : array ) { v . add ( i ) ; } int N = v . size ( ) ; maxPossibleDiff ( v , N ) ; } }
Reverse all elements of given circular array starting from index K | Java program for the above approach ; Function to print the array arr [ ] ; Print the array ; Function to reverse elements of given circular array starting from index k ; Initialize two variables as start = k and end = k - 1 ; Initialize count = N / 2 ; Loop while count > 0 ; Swap the elements at index ( start % N ) and ( end % N ) ; Update the start and end ; If end equals to - 1 set end = N - 1 ; Print the circular array ; Driver Code ; Function Call
class GFG { static void printArray ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } static void reverseCircularArray ( int arr [ ] , int N , int K ) { int start = K , end = K - 1 ; int count = N / 2 ; while ( count != 0 ) { int temp = arr [ start % N ] ; arr [ start % N ] = arr [ end % N ] ; arr [ end % N ] = temp ; start ++ ; end -- ; if ( end == - 1 ) { end = N - 1 ; } count -= 1 ; } printArray ( arr , N ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 5 , 2 , 4 , 1 } ; int K = 2 ; int N = arr . length ; reverseCircularArray ( arr , N , K ) ; } }