dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { public static boolean check ( int arr [ ] , int n ) { int count = 0 ; int index = - 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i - 1 ] >= arr [ i ] ) { count ++ ; index = i ; } } if ( count > 1 ) return false ; if ( count == 0 ) return true ; if ( index == n - 1 index == 1 ) return true ; if ( arr [ index - 1 ] < arr [ index + 1 ] ) return true ; if ( index - 2 >= 0 && arr [ index - 2 ] < arr [ index ] ) return true ; if ( index < 0 ) return true ; return false ; } public static void main ( String args [ ] ) { int [ ] arr = { 1 , 2 , 5 , 3 , 5 } ; int N = arr . length ; if ( check ( arr , N ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, index
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static void sortVowels ( String S ) { int n = S . length ( ) ; String vow = " " ; for ( int i = 0 ; i < n ; i ++ ) { if ( S . charAt ( i ) == ' a ' || S . charAt ( i ) == ' e ' || S . charAt ( i ) == ' i ' || S . charAt ( i ) == ' o ' || S . charAt ( i ) == ' u ' ) { vow = vow . substring ( 0 , vow . length ( ) ) + S . charAt ( i ) ; } } if ( vow . length ( ) == 0 ) { System . out . print ( S ) ; return ; } char tempArray [ ] = vow . toCharArray ( ) ; Arrays . sort ( tempArray ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( S . charAt ( i ) == ' a ' || S . charAt ( i ) == ' e ' || S . charAt ( i ) == ' i ' || S . charAt ( i ) == ' o ' || S . charAt ( i ) == ' u ' ) { S = S . substring ( 0 , i ) + tempArray [ j ++ ] + S . substring ( i + 1 , n ) ; } } System . out . print ( S ) ; } public static void main ( String [ ] args ) { String S = " geeksforgeeks " ; sortVowels ( S ) ; } }

Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { static void getBuckets ( int [ ] arr , int N ) { int availableWater = N * ( N - 1 ) / 2 ; Arrays . sort ( arr ) ; int i = 0 , sum = 0 ; while ( sum <= availableWater ) { sum += arr [ i ] ; i ++ ; } System . out . println ( i - 1 ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 5 , 3 , 4 , 7 , 9 } ; int N = arr . length ; getBuckets ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void minimumIncreasingSubsequences ( int arr [ ] , int N ) { Arrays . sort ( arr ) ; int count = 0 ; int i = 0 ; while ( i < N ) { int x = arr [ i ] ; int freqX = 0 ; while ( i < N && arr [ i ] == x ) { freqX ++ ; i ++ ; } count = Math . max ( count , freqX ) ; } System . out . print ( count ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 1 , 2 , 1 , 4 , 3 } ; int N = arr . length ; minimumIncreasingSubsequences ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: freqX, i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int getCount ( int arr [ ] , int N ) { Arrays . sort ( arr ) ; int count = 0 ; if ( N < 3 ) return 0 ; for ( int b = 0 ; b < N ; b ++ ) { int a = 0 , c = N - 1 ; int d = arr [ b ] * arr [ b ] / 4 ; while ( a < c ) { if ( a == b ) { a ++ ; continue ; } if ( c == b ) { c -- ; continue ; } if ( arr [ a ] * arr <= d ) { if ( a < b && b < c ) { count += c - a - 1 ; } else { count += c - a ; } a ++ ; } else { c -- ; } } } return count * 2 ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 6 , 10 , 13 , 21 } ; int N = arr . length ; System . out . print ( getCount ( arr , N ) ) ; } }

Index/key variables: a, b
Accumulator variables: a, b, c, count
Iterator variables: b
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findMaxDifference ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int Leftsum = 0 ; int Totalsum = 0 ; int Min = Integer . MAX_VALUE , Max = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) Totalsum += arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) { int leftNumbers = i ; int rightNumbers = n - i - 1 ; Totalsum = Totalsum - arr [ i ] ; int sum = ( leftNumbers * arr [ i ] ) - Leftsum + Totalsum - ( rightNumbers * arr [ i ] ) ; Min = Math . min ( Min , sum ) ; Max = Math . max ( Max , sum ) ; Leftsum += arr [ i ] ; } System . out . print ( Max - Min ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 , 7 } ; int N = arr . length ; findMaxDifference ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: Leftsum, Totalsum, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxcntPairsSumKRemoved ( int [ ] arr , int k ) { int cntPairs = 0 ; if ( arr . length <= 1 ) return cntPairs ; Arrays . sort ( arr ) ; int left = 0 ; int right = arr . length - 1 ; while ( left < right ) { int s = arr [ left ] + arr [ right ] ; if ( s == k ) { cntPairs += 1 ; left += 1 ; right -= 1 ; } else if ( s > k ) right -= 1 ; else left += 1 ; } return cntPairs ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 } ; int K = 5 ; System . out . println ( maxcntPairsSumKRemoved ( arr , K ) ) ; } }

Index/key variables: left, right
Accumulator variables: cntPairs, left, right
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void reverse ( int a [ ] , int n ) { int i , k , t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } } static int getMinCost ( int [ ] arr , int n , int k ) { Arrays . sort ( arr ) ; reverse ( arr , n ) ; int min_cost = 0 ; int X = 0 ; for ( int i = 0 ; i < n ; i += k ) { for ( int j = i ; j < i + k && j < n ; j ++ ) { min_cost += arr [ j ] * ( X + 1 ) ; } X ++ ; } return min_cost ; } public static void main ( String [ ] args ) { int arr [ ] = { 9 , 20 , 7 , 8 } ; int K = 2 ; int N = arr . length ; System . out . println ( getMinCost ( arr , N , K ) ) ; } }

Index/key variables: i, j
Accumulator variables: X, i, j, min_cost
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minDiff ( int [ ] A , int K ) { Arrays . sort ( A ) ; int n = A . length ; if ( n <= K ) return 0 ; int mindiff = A [ n - 1 ] - A [ 0 ] ; if ( K == 0 ) return mindiff ; for ( int i = 0 , j = n - 1 - K ; j < n ; ) { mindiff = Math . min ( mindiff , A [ j ] - A [ i ] ) ; i ++ ; j ++ ; } return mindiff ; } public static void main ( String [ ] args ) { int A [ ] = { - 1 , 3 , - 1 , 8 , 5 , 4 } ; int K = 3 ; System . out . println ( minDiff ( A , K ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int minDiff ( int [ ] A , int K ) { if ( A . length <= K + 1 ) return 0 ; PriorityQueue < Integer > maxHeap = new PriorityQueue < > ( ) ; PriorityQueue < Integer > minHeap = new PriorityQueue < > ( Collections . reverseOrder ( ) ) ; for ( int n : A ) { maxHeap . add ( n ) ; if ( maxHeap . size ( ) > K + 1 ) maxHeap . poll ( ) ; minHeap . add ( n ) ; if ( minHeap . size ( ) > K + 1 ) minHeap . poll ( ) ; } List < Integer > maxList = new ArrayList < > ( ) ; while ( maxHeap . size ( ) > 0 ) maxList . add ( maxHeap . poll ( ) ) ; List < Integer > minList = new ArrayList < > ( ) ; while ( minHeap . size ( ) > 0 ) minList . add ( minHeap . poll ( ) ) ; int mindiff = Integer . MAX_VALUE ; for ( int i = 0 ; i <= K ; i ++ ) { mindiff = Math . min ( mindiff , maxList . get ( i ) - minList . get ( K - i ) ) ; } return mindiff ; } public static void main ( String [ ] args ) { int A [ ] = { - 1 , 3 , - 1 , 8 , 5 , 4 } ; int K = 3 ; System . out . println ( minDiff ( A , K ) ) ; } }

Accumulator variables: i
Iterator variables: i, n
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void sortArrayInDescAsc ( int arr [ ] , int N , int K ) { Arrays . sort ( arr ) ; for ( int i = 0 , j = N - 1 ; i < N / 2 ; i ++ ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; j -- ; } Arrays . sort ( arr , K , N ) ; for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 6 , 8 , 9 , 0 , 1 , 2 , 2 , 1 , 8 , 9 , 6 , 7 } ; int N = arr . length ; int K = 6 ; sortArrayInDescAsc ( arr , N , K ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findMedianOfsubSum ( int arr [ ] , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; } Arrays . sort ( arr ) ; int [ ] [ ] dp = new int [ N ] [ sum + 1 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < sum + 1 ; j ++ ) dp [ i ] [ j ] = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = 1 ; } dp [ 0 ] [ arr [ 0 ] ] = 1 ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( j >= arr [ i ] ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - arr [ i ] ] ; } else { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; } } } Vector < Integer > sumSub = new Vector < Integer > ( ) ; for ( int j = 1 ; j <= sum ; j ++ ) { int M = dp [ N - 1 ] [ j ] ; for ( int i = 1 ; i <= M ; i ++ ) { sumSub . add ( j ) ; } } int mid = sumSub . get ( sumSub . size ( ) / 2 ) ; return mid ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 3 , 3 } ; int N = arr . length ; System . out . print ( findMedianOfsubSum ( arr , N ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printIndex ( int arr [ ] , int N ) { int [ ] B = new int [ N ] ; int save = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { B [ i ] = arr [ i ] ; } Arrays . sort ( B ) ; for ( int i = N - 1 ; i >= 1 ; i -- ) { if ( B [ i ] != B [ i - 1 ] ) { save = B [ i ] ; break ; } } if ( save == - 1 ) { System . out . print ( - 1 + "NEW_LINE"); return ; } if ( save == arr [ 0 ] && save != arr [ 1 ] ) { System . out . print ( 1 ) ; } else if ( save == arr [ N - 1 ] && save != arr [ N - 2 ] ) { System . out . print ( N ) ; } for ( int i = 1 ; i < N - 1 ; i ++ ) { if ( save == arr [ i ] && ( save != arr [ i - 1 ] save != arr [ i + 1 ] ) ) { System . out . print ( i + 1 ) ; break ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 3 , 4 , 4 , 5 } ; int N = arr . length ; printIndex ( arr , N ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void firstSubsequence ( String s ) { Vector < String > allsubseq = new Vector < > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { String k = " " ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { if ( i != j ) { k += s . charAt ( j ) ; } } allsubseq . add ( k ) ; } Collections . sort ( allsubseq ) ; System . out . print ( allsubseq . get ( 0 ) ) ; } public static void main ( String [ ] args ) { String S = " geeksforgeeks " ; firstSubsequence ( S ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int evenSumK ( int arr [ ] , int N , int K ) { if ( K > N ) { return - 1 ; } int maxSum = 0 ; ArrayList < Integer > Even = new ArrayList < Integer > ( ) ; ArrayList < Integer > Odd = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { Odd . add ( arr [ i ] ) ; } else { Even . add ( arr [ i ] ) ; } } Collections . sort ( Odd ) ; Collections . sort ( Even ) ; int i = Even . size ( ) - 1 ; int j = Odd . size ( ) - 1 ; while ( K > 0 ) { if ( K % 2 == 1 ) { if ( i >= 0 ) { maxSum += Even . get ( i ) ; i -- ; } else { return - 1 ; } K -- ; } else if ( i >= 1 && j >= 1 ) { if ( Even . get ( i ) + Even . get ( i - 1 ) <= Odd . get ( j ) + Odd . get ( j - 1 ) ) { maxSum += Odd . get ( j ) + Odd . get ( j - 1 ) ; j -= 2 ; } else { maxSum += Even . get ( i ) + Even . get ( i - 1 ) ; i -= 2 ; } K -= 2 ; } else if ( i >= 1 ) { maxSum += Even . get ( i ) + Even . get ( i - 1 ) ; i -= 2 ; K -= 2 ; } else if ( j >= 1 ) { maxSum += Odd . get ( j ) + Odd . get ( j - 1 ) ; j -= 2 ; K -= 2 ; } } return maxSum ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 10 , 3 , 5 } ; int N = arr . length ; int K = 3 ; System . out . println ( evenSumK ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: K, i, j, maxSum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Pair implements Comparable < Pair > { int first ; double second ; Pair ( int f , double s ) { first = f ; second = s ; } @ Override public int compareTo ( Pair o ) { if ( this . second > o . second ) return 1 ; else if ( this . second == o . second ) return 0 ; return - 1 ; } } static void weightedMedian ( Vector < Integer > arr , Vector < Double > W ) { Vector < Pair > pr = new Vector < > ( ) ; for ( int index = 0 ; index < arr . size ( ) ; index ++ ) pr . add ( new Pair ( arr . get ( index ) , W . get ( index ) ) ) ; Collections . sort ( pr ) ; if ( arr . size ( ) % 2 != 0 ) { float sums = 0 ; for ( Pair element : pr ) { sums += element . second ; if ( sums > 0.5 ) System . out . print ( " The ▁ Weighted ▁ Median ▁ is ▁ element ▁ " + element . first + "NEW_LINE"); } } else { double sums = 0 ; for ( Pair element : pr ) { sums += element . second ; if ( sums <= 0.5 ) { System . out . print ( " Lower ▁ Weighted ▁ Median ▁ is ▁ element ▁ " + element . first + "NEW_LINE"); break ; } } sums = 0 ; for ( int index = pr . size ( ) - 1 ; index >= 0 ; index -- ) { int element = pr . get ( index ) . first ; double weight = pr . get ( index ) . second ; sums += weight ; if ( sums >= 0.5 ) { System . out . print ( " Upper ▁ Weighted ▁ Median ▁ is ▁ element ▁ " + element ) ; break ; } } } } public static void main ( String [ ] args ) { Vector < Integer > arr = new Vector < > ( ) ; arr . add ( 4 ) ; arr . add ( 1 ) ; arr . add ( 3 ) ; arr . add ( 2 ) ; Vector < Double > W = new Vector < > ( ) ; W . add ( 0.25 ) ; W . add ( 0.49 ) ; W . add ( 0.25 ) ; W . add ( 0.01 ) ; weightedMedian ( arr , W ) ; } }

Accumulator variables: index, sums
Iterator variables: element, index
Class/struct names: GFG, Pair
Java program:
import java . util . * ; import java . io . * ; class GFG { public static int KthSmallestNum ( int arr [ ] [ ] , int n , int k ) { PriorityQueue < int [ ] > pq = new PriorityQueue < > ( ( a , b ) -> a [ 0 ] - b [ 0 ] ) ; for ( int i = 0 ; i < n ; i ++ ) { pq . add ( new int [ ] { arr [ i ] [ 0 ] , arr [ i ] [ 1 ] } ) ; } int cnt = 1 ; while ( cnt < k ) { int [ ] interval = pq . poll ( ) ; if ( interval [ 0 ] < interval [ 1 ] ) { pq . add ( new int [ ] { interval [ 0 ] + 1 , interval [ 1 ] } ) ; } cnt ++ ; } return pq . peek ( ) [ 0 ] ; } public static void main ( String args [ ] ) { int arr [ ] [ ] = { { 5 , 11 } , { 10 , 15 } , { 12 , 20 } } ; int n = arr . length ; int k = 12 ; System . out . println ( KthSmallestNum ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static class Pair { int x ; int y ; Pair ( int x , int y ) { this . x = x ; this . y = y ; } } static void MaxDist ( ArrayList < Pair > A , int N ) { int maximum = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { int sum = 0 ; for ( int j = i + 1 ; j < N ; j ++ ) { sum = Math . abs ( A . get ( i ) . x - A . get ( j ) . x ) + Math . abs ( A . get ( i ) . y - A . get ( j ) . y ) ; maximum = Math . max ( maximum , sum ) ; } } System . out . println ( maximum ) ; } public static void main ( String [ ] args ) { int n = 3 ; ArrayList < Pair > al = new ArrayList < > ( ) ; Pair p1 = new Pair ( 1 , 2 ) ; al . add ( p1 ) ; Pair p2 = new Pair ( 2 , 3 ) ; al . add ( p2 ) ; Pair p3 = new Pair ( 3 , 4 ) ; al . add ( p3 ) ; MaxDist ( al , n ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, Pair
Java program:
import java . io . * ; import java . util . * ; class GFG { static int LongestSequence ( int a [ ] , int n ) { HashMap < Integer , Integer > m = new HashMap < > ( ) ; int ar [ ] = new int [ n + 1 ] ; int i = 0 ; int j = 0 ; for ( i = 1 ; i <= n ; i ++ ) { ar [ i ] = a [ i - 1 ] ; } Arrays . sort ( a ) ; int c = 1 ; m . put ( a [ 0 ] , c ) ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] != a [ i - 1 ] ) { c ++ ; m . put ( a [ i ] , c ) ; } } HashMap < Integer , Integer > cnt = new HashMap < > ( ) ; int dp [ ] [ ] = new int [ n + 1 ] [ 3 ] ; cnt . put ( 0 , 0 ) ; for ( i = 1 ; i <= n ; i ++ ) { ar [ i ] = m . get ( ar [ i ] ) ; if ( cnt . containsKey ( ar [ i ] ) ) cnt . put ( ar [ i ] , cnt . get ( ar [ i ] ) + 1 ) ; else cnt . put ( ar [ i ] , 1 ) ; } int ans = 0 , x ; for ( i = 1 ; i <= n ; i ++ ) { x = ar [ i ] ; if ( dp [ x ] [ 0 ] == 0 ) { if ( dp [ x - 1 ] [ 0 ] == cnt . get ( x - 1 ) ) { dp [ x ] [ 1 ] = dp [ x - 1 ] [ 1 ] ; dp [ x ] [ 2 ] = dp [ x - 1 ] [ 1 ] ; } else { dp [ x ] [ 1 ] = dp [ x - 1 ] [ 0 ] ; } } dp [ x ] [ 2 ] = Math . max ( dp [ x - 1 ] [ 0 ] , dp [ x ] [ 2 ] ) ; if ( dp [ x - 1 ] [ 0 ] == cnt . get ( x - 1 ) ) { dp [ x ] [ 2 ] = Math . max ( dp [ x ] [ 2 ] , dp [ x - 1 ] [ 1 ] ) ; } for ( j = 0 ; j < 3 ; j ++ ) { dp [ x ] [ j ] ++ ; ans = Math . max ( ans , dp [ x ] [ j ] ) ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 6 , 4 , 8 , 2 , 9 } ; int n = arr . length ; System . out . println ( LongestSequence ( arr , n ) ) ; } } System . out . println ( LongestSequence ( arr , n ) ) ; }

Index/key variables: i, j, x
Accumulator variables: c, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int [ ] [ ] findMatrix ( int N , int K ) { int [ ] [ ] mat = new int [ N ] [ N ] ; int element = 1 ; for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < K - 1 ; ++ j ) { mat [ i ] [ j ] = element ++ ; } } for ( int i = 0 ; i < N ; ++ i ) { for ( int j = K - 1 ; j < N ; ++ j ) { mat [ i ] [ j ] = element ++ ; } } return mat ; } static void printMatrix ( int [ ] [ ] mat , int N ) { for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) { System . out . print ( mat [ i ] [ j ] + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int N = 3 , K = 2 ; int [ ] [ ] mat = findMatrix ( N , K ) ; printMatrix ( mat , N ) ; } }

Index/key variables: N, i, j
Accumulator variables: element
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int range_sum ( int [ ] arr , int a , int b ) { int sum = 0 ; if ( a - 2 < 0 ) sum = arr [ b - 1 ] ; else sum = arr [ b - 1 ] - arr [ a - 2 ] ; return sum ; } static void precompute_sum ( int [ ] arr , int [ ] brr ) { int N = ( int ) arr . length ; for ( int i = 1 ; i < N ; i ++ ) { arr [ i ] = arr [ i ] + arr [ i - 1 ] ; brr [ i ] = brr [ i ] + brr [ i - 1 ] ; } } static void find_sum ( int [ ] arr , int q , int Queries [ ] [ ] ) { int [ ] brr = arr . clone ( ) ; int N = ( int ) arr . length ; Arrays . sort ( brr ) ; precompute_sum ( arr , brr ) ; for ( int i = 0 ; i < q ; i ++ ) { int m = Queries [ i ] [ 0 ] ; int a = Queries [ i ] [ 1 ] ; int b = Queries [ i ] [ 2 ] ; if ( m == 1 ) { System . out . print ( range_sum ( arr , a , b ) + " ▁ " ) ; } else if ( m == 2 ) { System . out . print ( range_sum ( brr , a , b ) + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int [ ] arr = { 0 , 6 , 4 , 2 , 7 , 2 , 7 } ; int Q = 1 ; int Queries [ ] [ ] = { { 2 , 3 , 6 } } ; find_sum ( arr , Q , Queries ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int lower_bound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } static int XorSum ( int A [ ] , int B [ ] , int N ) { final int maxBit = 29 ; int ans = 0 ; for ( int k = 0 ; k < maxBit ; k ++ ) { int [ ] C = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { C [ i ] = B [ i ] % ( 1 << ( k + 1 ) ) ; } Arrays . sort ( C ) ; long count = 0 ; long l , r ; for ( int i = 0 ; i < N ; i ++ ) { int x = A [ i ] % ( 1 << ( k + 1 ) ) ; l = lower_bound ( C , 0 , N , ( 1 << k ) - x ) ; r = lower_bound ( C , 0 , N , ( 1 << k ) * 2 - x ) ; count += ( r - l ) ; l = lower_bound ( C , 0 , N , ( 1 << k ) * 3 - x ) ; r = lower_bound ( C , 0 , N , ( 1 << k ) * 4 - x ) ; count += ( r - l ) ; } if ( ( count & 1 ) != 0 ) ans += ( 1 << k ) ; } return ans ; } public static void main ( String [ ] args ) { int A [ ] = { 4 , 6 , 0 , 0 , 3 , 3 } ; int B [ ] = { 0 , 5 , 6 , 5 , 0 , 3 } ; int N = A . length ; System . out . print ( XorSum ( A , B , N ) + "NEW_LINE"); } }

Index/key variables: N, i, middle
Accumulator variables: ans, count, i, k
Iterator variables: i, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findCount ( int arr [ ] , int N , int K ) { Arrays . sort ( arr ) ; int result = 1 ; int cur_max = arr [ 0 ] ; int cur_min = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { cur_max = arr [ i ] ; if ( cur_max - cur_min > K ) { result ++ ; cur_max = arr [ i ] ; cur_min = arr [ i ] ; } } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 10 , 8 , 3 , 9 } ; int K = 3 ; int N = arr . length ; System . out . print ( findCount ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: i, result
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int mod = ( int ) 1e9 + 7 ; static int findMinValue ( int [ ] a , int [ ] b ) { int n = a . length ; int [ ] pro = new int [ n ] ; for ( int i = 0 ; i < n ; ++ i ) { pro [ i ] = ( ( i + 1 ) * ( n - i ) ) ; pro [ i ] *= ( 1L * a [ i ] ) ; ; } Integer [ ] input = Arrays . stream ( b ) . boxed ( ) . toArray ( Integer [ ] :: new ) ; Arrays . sort ( input , ( x , y ) -> y - x ) ; b = Arrays . stream ( input ) . mapToInt ( Integer :: intValue ) . toArray ( ) ; Arrays . sort ( pro ) ; int ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) { ans += ( pro [ i ] % mod * b [ i ] ) % mod ; ans %= mod ; } return ans ; } public static void main ( String [ ] args ) { int [ ] a = { 1 , 2 , 3 } ; int [ ] b = { 2 , 3 , 2 } ; System . out . print ( findMinValue ( a , b ) + "NEW_LINE"); } }

Index/key variables: i, n
Accumulator variables: ans
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static class pair { int first , second ; pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void findTriplets ( int arr [ ] , int n ) { Map < Integer , Integer > mp = new HashMap < > ( ) ; for ( int x = 0 ; x < n ; x ++ ) mp . put ( arr [ x ] , mp . getOrDefault ( arr [ x ] , 0 ) + 1 ) ; PriorityQueue < pair > pq = new PriorityQueue < > ( ( a , b ) -> a . first - b . first ) ; for ( Map . Entry < Integer , Integer > k : mp . entrySet ( ) ) pq . add ( new pair ( k . getValue ( ) , k . getKey ( ) ) ) ; ArrayList < List < Integer > > ans = new ArrayList < > ( ) ; while ( pq . size ( ) >= 3 ) { pair [ ] ar = new pair [ 3 ] ; for ( int x = 0 ; x < 3 ; x ++ ) { ar [ x ] = pq . peek ( ) ; pq . poll ( ) ; } ans . add ( Arrays . asList ( ar [ 0 ] . second , ar [ 1 ] . second , ar [ 2 ] . second ) ) ; for ( int x = 0 ; x < 3 ; x ++ ) { ar [ x ] . first -- ; if ( ar [ x ] . first != 0 ) pq . add ( ar [ x ] ) ; } } System . out . println ( " Maximum ▁ number ▁ of ▁ " + " possible ▁ triples : ▁ " + ans . size ( ) ) ; for ( List < Integer > pa : ans ) { for ( Integer v : pa ) System . out . print ( v + " ▁ " ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 3 , 3 , 4 , 4 , 4 , 4 , 5 } ; int n = arr . length ; findTriplets ( arr , n ) ; } }

Index/key variables: x
Accumulator variables: first, x
Iterator variables: pa, v, x
Class/struct names: GFG, pair