codeparrot/xlcost-text-to-code huggingface dataset:
Check if the sum of K least and most frequent array elements are equal or not | Java program for the above approach ; Function to compare the sum of K most and least occurrences ; Stores frequency of array element ; Stores the frequencies as indexes and putelements with the frequency in a vector ; Find the frequency ; Insert in the vector ; Stores the count of elements ; Traverse the frequency array ; Find the kleastfreqsum ; If the count is K , break ; Reinitialize the count to zero ; Traverse the frequency ; Find the kmostfreqsum ; If the count is K , break ; Comparing the sum ; Otherwise , return No ; Driver Code
import java . util . * ; class GFG { static String checkSum ( int arr [ ] , int n , int k ) { HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( m . containsKey ( arr [ i ] ) ) { m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; } else { m . put ( arr [ i ] , 1 ) ; } Vector < Integer > [ ] freq = new Vector [ n + 1 ] ; for ( int i = 0 ; i < freq . length ; i ++ ) freq [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int f = m . get ( arr [ i ] ) ; if ( f != - 1 ) { freq [ f ] . add ( arr [ i ] ) ; m . put ( arr [ i ] , - 1 ) ; } } int count = 0 ; int kleastfreqsum = 0 ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int x : freq [ i ] ) { kleastfreqsum += x ; count ++ ; if ( count == k ) break ; } if ( count == k ) break ; } count = 0 ; int kmostfreqsum = 0 ; for ( int i = n ; i >= 0 ; i -- ) { for ( int x : freq [ i ] ) { kmostfreqsum += x ; count ++ ; if ( count == k ) break ; } if ( count == k ) break ; } if ( kleastfreqsum == kmostfreqsum ) return " Yes " ; return " No " ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 1 , 2 , 3 , 3 , 4 } ; int N = arr . length ; int K = 2 ; System . out . print ( checkSum ( arr , N , K ) ) ; } }
Print all numbers from a given range that are made up of consecutive digits | Java program for the above approach ; Function to find the consecutive digit numbers in the given range ; Initialize num as empty String ; Stores the resultant number ; Iterate over the range [ 1 , 9 ] ; Check if the current number is within range ; Iterate on the digits starting from i ; Checking the consecutive digits numbers starting from i and ending at j is within range or not ; Sort the numbers in the increasing order ; Driver Code ; Print the required numbers
import java . util . * ; class GFG { static Vector < Integer > solve ( int start , int end ) { String num = " " ; Vector < Integer > ans = new Vector < > ( ) ; for ( int i = 1 ; i <= 9 ; i ++ ) { num = Integer . toString ( i ) ; int value = i ; if ( value >= start && value <= end ) { ans . add ( value ) ; } for ( int j = i + 1 ; j <= 9 ; j ++ ) { num += Integer . toString ( j ) ; value = Integer . valueOf ( num ) ; if ( value >= start && value <= end ) { ans . add ( value ) ; } } } Collections . sort ( ans ) ; ; return ans ; } public static void main ( String [ ] args ) { int L = 12 , R = 87 ; Vector < Integer > ans = solve ( L , R ) ; for ( int it : ans ) System . out . print ( it + " ▁ " ) ; } }
Minimum distance a person has to move in order to take a picture of every racer | Java implementation for the above approach ; Function to return the minimum distance the person has to move int order to get the pictures ; To store the minimum ending point ; To store the maximum starting point ; Find the values of minSeg and maxSeg ; Impossible ; The person doesn 't need to move ; Get closer to the left point ; Get closer to the right point ; Driver code
import java . io . * ; class GFG { static int minDistance ( int start [ ] , int end [ ] , int n , int d ) { int left = Integer . MIN_VALUE ; int right = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { left = Math . max ( left , start [ i ] ) ; right = Math . min ( right , end [ i ] ) ; } if ( left > right ) return - 1 ; if ( d >= left && d <= right ) return 0 ; if ( d < left ) return ( left - d ) ; if ( d > right ) return ( d - right ) ; return - 1 ; } public static void main ( String [ ] args ) { int start [ ] = { 0 , 2 , 4 } ; int end [ ] = { 7 , 14 , 6 } ; int n = start . length ; int d = 3 ; System . out . println ( minDistance ( start , end , n , d ) ) ; } }
Maximum number of Armstrong Numbers present in a subarray of size K | Java program for above approach ; Function to calculate the value of x raised to the power y in O ( log y ) ; Base Case ; If the power y is even ; Otherwise ; Function to calculate the order of the number , i . e . count of digits ; Stores the total count of digits ; Iterate until num is 0 ; Function to check a number is an Armstrong Number or not ; Find the order of the number ; Check for Armstrong Number ; If Armstrong number condition is satisfied ; Utility function to find the maximum sum of a subarray of size K ; If k is greater than N ; Find the sum of first subarray of size K ; Find the sum of the remaining subarray ; Return the maximum sum of subarray of size K ; Function to find all the Armstrong Numbers in the array ; Traverse the array arr [ ] ; If arr [ i ] is an Armstrong Number , then replace it by 1. Otherwise , 0 ; Return the resultant count ; Driver Code
import java . util . * ; class GFG { static int power ( int x , int y ) { if ( y == 0 ) return 1 ; if ( y % 2 == 0 ) return power ( x , y / 2 ) * power ( x , y / 2 ) ; return x * power ( x , y / 2 ) * power ( x , y / 2 ) ; } static int order ( int num ) { int count = 0 ; while ( num > 0 ) { count ++ ; num = num / 10 ; } return count ; } static int isArmstrong ( int N ) { int r = order ( N ) ; int temp = N , sum = 0 ; while ( temp > 0 ) { int d = temp % 10 ; sum += power ( d , r ) ; temp = temp / 10 ; } if ( sum == N ) return 1 ; return 0 ; } static int maxSum ( int [ ] arr , int N , int K ) { if ( N < K ) { return - 1 ; } int res = 0 ; for ( int i = 0 ; i < K ; i ++ ) { res += arr [ i ] ; } int curr_sum = res ; for ( int i = K ; i < N ; i ++ ) { curr_sum += arr [ i ] - arr [ i - K ] ; res = Math . max ( res , curr_sum ) ; } return res ; } static int maxArmstrong ( int [ ] arr , int N , int K ) { for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = isArmstrong ( arr [ i ] ) ; } return maxSum ( arr , N , K ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 28 , 2 , 3 , 6 , 153 , 99 , 828 , 24 } ; int K = 6 ; int N = arr . length ; System . out . println ( maxArmstrong ( arr , N , K ) ) ; } }
Count N | Java program for the above approach ; Function to calculate the power of n ^ k % p ; Update x if it is more than or equal to p ; In case x is divisible by p ; ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; Function to count the number of arrays satisfying required conditions ; Calculating N ^ K ; Driver Code
import java . io . * ; class GFG { static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } static int countArrays ( int n , int k ) { int mod = 1000000007 ; int ans = power ( n , k , mod ) ; return ans ; } public static void main ( String [ ] args ) { int n = 3 , k = 5 ; int ans = countArrays ( n , k ) ; System . out . println ( ans ) ; } }
Count ways to replace ' ? ' in a Binary String to make the count of 0 s and 1 s same as that of another string | Java program for above approach ; Function to find the factorial of the given number N ; Stores the factorial ; Iterate over the range [ 2 , N ] ; Return the resultant result ; Function to find the number of ways of choosing r objects from n distinct objects ; Function to find the number of ways to replace ' ? ' in string t to get the same count of 0 s and 1 s in the string S and T ; Traverse the string s ; If the current character is 1 ; Update the value of the sum1 ; Otherwise ; Traverse the string t ; If the current character is 1 , then update the value of sum2 ; If the current character is 0 ; Otherwise , update the value of K ; Check if P is greater than K or if K - P is odd ; Print the count of ways ; Driver Code
import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . Map ; class GFG { static int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { res = res * i ; } return res ; } static int nCr ( int n , int r ) { return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } static void countWays ( String s , String t ) { int n = s . length ( ) ; int sum1 = 0 , sum2 = 0 , K = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '1' ) { sum1 ++ ; } else sum1 -- ; } int m = t . length ( ) ; for ( int i = 0 ; i < m ; i ++ ) { if ( t . charAt ( i ) == '1' ) { sum2 ++ ; } else if ( t . charAt ( i ) == '0' ) { sum2 -- ; } else K ++ ; } int P = Math . abs ( sum1 - sum2 ) ; if ( ( P > K ) || ( K - P ) % 2 == 1 ) { System . out . println ( 0 ) ; return ; } System . out . println ( nCr ( K , ( P + K ) / 2 ) ) ; } public static void main ( String [ ] args ) { String S1 = "1010" ; String S2 = "10 ? ? " ; countWays ( S1 , S2 ) ; } }
Count pairs of indices having sum of indices same as the sum of elements at those indices | Java program for the above approach ; Function to find all possible pairs of the given array such that the sum of arr [ i ] + arr [ j ] is i + j ; Stores the total count of pairs ; Iterate over the range ; Iterate over the range ; Print the total count ; Driver Code
class GFG { public static void countPairs ( int arr [ ] , int N ) { int answer = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( arr [ i ] + arr [ j ] == i + j ) { answer ++ ; } } } System . out . println ( answer ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 0 , 1 , 2 , 3 , 4 , 5 } ; int N = arr . length ; countPairs ( arr , N ) ; } }
Distribute R , B beans such that each packet has at least 1 R and 1 B bean with absolute difference at most D | Java program for the above approach ; Function to check if it is possible to distribute R red and B blue beans in packets such that the difference between the beans in each packet is atmost D ; Check for the condition to distributing beans ; Print the answer ; Distribution is not possible ; Driver Code
import java . io . * ; class GFG { static void checkDistribution ( int R , int B , int D ) { if ( Math . max ( R , B ) <= Math . min ( R , B ) * ( D + 1 ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { int R = 1 , B = 1 , D = 0 ; checkDistribution ( R , B , D ) ; } }
Generate a sequence with product N such that for every pair of indices ( i , j ) and i < j , arr [ j ] is divisible by arr [ i ] | Java program for the above approach ; Function to calculate the prime factors of N with their count ; Initialize a vector , say v ; Initialize the count ; Count the number of divisors ; Divide the value of N by 2 ; For factor 2 divides it ; Find all prime factors ; Count their frequency ; Push it to the vector ; Push N if it is not 1 ; Function to print the array that have the maximum size ; Stores the all prime factor and their powers ; Traverse the vector and find the maximum power of prime factor ; If max size is less than 2 ; Otherwise ; Print the maximum size of sequence ; Print the final sequence ; Print the prime factor ; Print the last value of the sequence ; Driver Code
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static Vector < pair > primeFactor ( int N ) { Vector < pair > v = new Vector < > ( ) ; int count = 0 ; while ( ( N % 2 ) == 0 ) { N >>= 1 ; count ++ ; } if ( count != 0 ) v . add ( new pair ( 2 , count ) ) ; for ( int i = 3 ; i <= Math . sqrt ( N ) ; i += 2 ) { count = 0 ; while ( N % i == 0 ) { count ++ ; N = N / i ; } if ( count != 0 ) { v . add ( new pair ( i , count ) ) ; } } if ( N > 2 ) v . add ( new pair ( N , 1 ) ) ; return v ; } static void printAnswer ( int n ) { Vector < pair > v = primeFactor ( n ) ; int maxi_size = 0 , prime_factor = 0 ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { if ( maxi_size < v . get ( i ) . second ) { maxi_size = v . get ( i ) . second ; prime_factor = v . get ( i ) . first ; } } if ( maxi_size < 2 ) { System . out . print ( 1 << ' ▁ ' ) ; } else { int product = 1 ; System . out . print ( maxi_size + "NEW_LINE"); for ( int i = 0 ; i < maxi_size - 1 ; i ++ ) { System . out . print ( prime_factor + " ▁ " ) ; product *= prime_factor ; } System . out . print ( ( n / product ) ) ; } } public static void main ( String [ ] args ) { int N = 360 ; printAnswer ( N ) ; } }
Check if it is possible to reach destination in even number of steps in an Infinite Matrix | Java program for the above approach ; Function to check destination can be reached from source in even number of steps ; Coordinates differences ; Minimum number of steps required ; Minsteps is even ; Minsteps is odd ; Driver code ; Given Input ; Function Call
import java . lang . * ; import java . util . * ; class GFG { static void IsEvenPath ( int Source [ ] , int Destination [ ] ) { int x_dif = Math . abs ( Source [ 0 ] - Destination [ 0 ] ) ; int y_dif = Math . abs ( Source [ 1 ] - Destination [ 1 ] ) ; int minsteps = x_dif + y_dif ; if ( minsteps % 2 == 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int Source [ ] = { 2 , 1 } ; int Destination [ ] = { 1 , 4 } ; IsEvenPath ( Source , Destination ) ; } }
Find the closest Fraction to given fraction having minimum absolute difference | Java code for the above approach ; Function to find the absolute value of x ; Function to find the fraction with minimum absolute difference ; Initialize the answer variables ; Iterate over the range ; Nearest fraction ; x / y - d / i < x / y - A / B ( B * x - y * A ) * ( i * y ) > ( i * x - y * d ) * ( B * y ) ; Check for d + 1 ; Print the answer ; Driver Code
import java . io . * ; class GFG { static long ABS ( long x ) { return Math . max ( x , - x ) ; } static void findFraction ( long x , long y , long n ) { long A = - 1 , B = - 1 ; for ( long i = 1 ; i <= n ; i ++ ) { long d = ( i * x ) / y ; if ( d >= 0 && ( A == - 1 || ABS ( B * x - y * A ) * ABS ( i * y ) > ABS ( i * x - y * d ) * ABS ( B * y ) ) ) A = d ; B = i ; d ++ ; if ( d >= 0 && ( A == - 1 || ABS ( B * x - y * A ) * ABS ( i * y ) > ABS ( i * x - y * d ) * ABS ( B * y ) ) ) A = d ; B = i ; } A -- ; B -- ; System . out . println ( A + " / " + B ) ; } public static void main ( String [ ] args ) { long x = 3 ; long y = 7 ; long n = 6 ; findFraction ( x , y , n ) ; } }
Represent a number N in base | Java Program for above approach ; Function to convert N to equivalent representation in base - 2 ; Stores the required answer ; Iterate until N is not equal to zero ; If N is Even ; Add char '0' in front of string ; Add char '1' in front of string ; Decrement N by 1 ; Divide N by - 2 ; If string is empty , that means N is zero ; Put '0' in string s ; Driver Code ; Given Input ; Function Call
class GFG { public static String BaseConversion ( int N ) { String s = " " ; while ( N != 0 ) { if ( N % 2 == 0 ) { s = "0" + s ; } else { s = "1" + s ; N -- ; } N /= - 2 ; } if ( s == " " ) { s = "0" ; } return s ; } public static void main ( String args [ ] ) { int N = - 9 ; System . out . println ( BaseConversion ( N ) ) ; } }
Find instances at end of time frame after auto scaling | Java program for above approach ; Function to find the number of instances after compintion ; Traverse the array , arr [ ] ; If current element is less than 25 ; Divide instances by 2 ; If the current element is greater than 60 ; Double the instances ; Print the instances at the end of the traversal ; Driver Code ; Function Call
class GFG { public static void finalInstances ( int instances , int [ ] arr ) { int i = 0 ; while ( i < arr . length ) { if ( arr [ i ] < 25 && instances > 1 ) { instances = ( instances / 2 ) ; i = i + 10 ; } else if ( arr [ i ] > 60 && instances <= Math . pow ( 10 , 8 ) ) { instances = instances * 2 ; i = i + 10 ; } i = i + 1 ; } System . out . println ( instances ) ; } public static void main ( String args [ ] ) { int instances = 2 ; int [ ] arr = { 25 , 23 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 76 , 80 } ; finalInstances ( instances , arr ) ; } }
Modify array by making all array elements equal to 0 by subtracting K ^ i from an array element in every i | Java program for the above approach ; Function to check whether all array elements can be made zero or not ; Stores if a power of K has already been subtracted or not ; Stores all the Kth power ; Iterate until X is less than INT_MAX ; Traverse the array arr [ ] ; Iterate over the range [ 0 , M ] ; If MP [ V [ j ] ] is 0 and V [ j ] is less than or equal to arr [ i ] ; If arr [ i ] is not 0 ; If i is less than N ; Otherwise , ; Driver code
import java . util . ArrayList ; import java . util . HashMap ; class GFG { static String isMakeZero ( int arr [ ] , int N , int K ) { HashMap < Integer , Integer > MP = new HashMap < Integer , Integer > ( ) ; ArrayList < Integer > V = new ArrayList < Integer > ( ) ; int X = 1 ; int i ; while ( X > 0 && X < Integer . MAX_VALUE ) { V . add ( X ) ; X *= K ; } for ( i = 0 ; i < N ; i ++ ) { for ( int j = V . size ( ) - 1 ; j >= 0 ; j -- ) { if ( MP . containsKey ( V . get ( j ) ) == false && V . get ( j ) <= arr [ i ] ) { arr [ i ] -= V . get ( j ) ; MP . put ( V . get ( j ) , 1 ) ; } } if ( arr [ i ] != 0 ) break ; } if ( i < N ) return " No " ; else return " Yes " ; } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 0 , 3 , 4 , 80 } ; int N = arr . length ; int K = 2 ; System . out . println ( isMakeZero ( arr , N , K ) ) ; } }
Check whether the product of every subsequence is a perfect square or not | Java program for the above approach ; Function to check if the product of every subsequence of the array is a perfect square or not ; Traverse the given array ; If arr [ i ] is a perfect square or not ; Return " Yes " ; Driver Code
import java . io . * ; class GFG { static String perfectSquare ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int p = ( int ) Math . sqrt ( arr [ i ] ) ; if ( p * p != arr [ i ] ) { return " No " ; } } return " Yes " ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 100 } ; int N = arr . length ; System . out . println ( perfectSquare ( arr , N ) ) ; } }
Count of subarrays with average K | Java implementation of above approach ; Function to count subarray having average exactly equal to K ; To Store the final answer ; Calculate all subarrays ; Calculate required average ; Check if average is equal to k ; Required average found ; Increment res ; Driver code ; Given Input ; Function Call
import java . io . * ; class GFG { static int countKAverageSubarrays ( int arr [ ] , int n , int k ) { int res = 0 ; for ( int L = 0 ; L < n ; L ++ ) { int sum = 0 ; for ( int R = L ; R < n ; R ++ ) { sum += arr [ R ] ; int len = ( R - L + 1 ) ; if ( sum % len == 0 ) { int avg = sum / len ; if ( avg == k ) res ++ ; } } } return res ; } public static void main ( String [ ] args ) { int K = 6 ; int arr [ ] = { 12 , 5 , 3 , 10 , 4 , 8 , 10 , 12 , - 6 , - 1 } ; int N = arr . length ; System . out . print ( countKAverageSubarrays ( arr , N , K ) ) ; } }
Maximize minimum array element possible by exactly K decrements | Java program for the above approach ; Function to find the maximized minimum element of the array after performing given operation exactly K times ; Stores the minimum element ; Traverse the given array ; Update the minimum element ; Stores the required operations to make all elements equal to the minimum element ; Update required operations ; If reqOperations < K ; Decrement the value of K by reqOperations ; Update minElement ; Return minimum element ; Driver Code
import java . io . * ; class GFG { static int minimumElement ( int arr [ ] , int N , int K ) { int minElement = arr [ 0 ] ; for ( int i = 0 ; i < N ; ++ i ) { minElement = Math . min ( minElement , arr [ i ] ) ; } int reqOperations = 0 ; for ( int i = 0 ; i < N ; ++ i ) { reqOperations += arr [ i ] - minElement ; } if ( reqOperations < K ) { K -= reqOperations ; minElement -= ( K + N - 1 ) / N ; } return minElement ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 10 , 10 , 10 } ; int K = 7 ; int N = arr . length ; System . out . println ( minimumElement ( arr , N , K ) ) ; } }
Split the fraction into sum of multiple fractions having numerator as 1 | Java program for the above approach ; Function to split the fraction into distinct unit fraction ; To store answer ; While numerator is positive ; Finding x = ceil ( d / n ) ; Add 1 / x to list of ans ; Update fraction ; Driver code ; Given Input ; Function Call ; Print Answer
import java . util . Vector ; public class GFG { static Vector < String > FractionSplit ( long n , long d ) { Vector < String > UnitFactions = new Vector < > ( ) ; while ( n > 0 ) { long x = ( d + n - 1 ) / n ; String s = "1 / " + String . valueOf ( x ) ; UnitFactions . add ( s ) ; n = n * x - d ; d = d * x ; } return UnitFactions ; } public static void main ( String [ ] args ) { long n = 13 , d = 18 ; Vector < String > res = FractionSplit ( n , d ) ; for ( String s : res ) System . out . print ( s + " , ▁ " ) ; } }
Find permutation of [ 1 , N ] such that ( arr [ i ] != i + 1 ) and sum of absolute difference between arr [ i ] and ( i + 1 ) is minimum | Function to generate the permutation of the first N natural numbers having sum of absolute difference between element and indices as minimum ; Initialize array arr [ ] from 1 to N ; Swap alternate positions ; Check N is greater than 1 and N is odd ; Swapping last two positions ; Print the permutation ; Driver code
import java . util . * ; class GFG { static void findPermutation ( int N ) { int [ ] arr = new int [ N ] ; int temp ; for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = i + 1 ; } for ( int i = 1 ; i < N ; i += 2 ) { temp = arr [ i ] ; arr [ i ] = arr [ i - 1 ] ; arr [ i - 1 ] = temp ; } if ( N % 2 == 1 && N > 1 ) { temp = arr [ N - 1 ] ; arr [ N - 1 ] = arr [ N - 2 ] ; arr [ N - 2 ] = temp ; } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 7 ; findPermutation ( N ) ; } }
Find Array obtained after adding terms of AP for Q queries | Java program for the above approach ; Function to find array after performing the given query to the array elements ; Traverse the given query ; Traverse the given array ; Update the value of A [ i ] ; Update the value of curr ; Print the array elements ; Driver Code ; Function Call
class GFG { public static void addAP ( int A [ ] , int Q , int [ ] [ ] operations ) { for ( int j = 0 ; j < 2 ; ++ j ) { int L = operations [ j ] [ 0 ] , R = operations [ j ] [ 1 ] , a = operations [ j ] [ 2 ] , d = operations [ j ] [ 3 ] ; int curr = a ; for ( int i = L - 1 ; i < R ; i ++ ) { A [ i ] += curr ; curr += d ; } } for ( int i = 0 ; i < 4 ; ++ i ) System . out . print ( A [ i ] + " ▁ " ) ; } public static void main ( String args [ ] ) { int A [ ] = { 5 , 4 , 2 , 8 } ; int Q = 2 ; int query [ ] [ ] = { { 1 , 2 , 1 , 3 } , { 1 , 4 , 4 , 1 } } ; addAP ( A , Q , query ) ; } }