dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class FrequentWords { public static ArrayList < String > frequentWords ( ArrayList < String > arr , int K ) { HashMap < String , Integer > Freq = new HashMap < > ( ) ; for ( String word : arr ) { Freq . put ( word , Freq . getOrDefault ( word , 0 ) + 1 ) ; } PriorityQueue < String > Order = new PriorityQueue < > ( ( a , b ) -> ( Freq . get ( a ) != Freq . get ( b ) ) ? Freq . get ( a ) - Freq . get ( b ) : b . compareTo ( a ) ) ; for ( String word : Freq . keySet ( ) ) { Order . offer ( word ) ; if ( Order . size ( ) > K ) { Order . poll ( ) ; } } ArrayList < String > ans = new ArrayList < > ( ) ; while ( ! Order . isEmpty ( ) ) { ans . add ( Order . poll ( ) ) ; } Collections . reverse ( ans ) ; return ans ; } public static void main ( String [ ] args ) { int N = 3 , K = 2 ; ArrayList < String > arr = new ArrayList < String > ( ) ; arr . add ( " car " ) ; arr . add ( " bus " ) ; arr . add ( " car " ) ; ArrayList < String > ans = frequentWords ( arr , K ) ; for ( String word : ans ) { System . out . println ( word + " ▁ " ) ; } } }

Iterator variables: word
Class/struct names: FrequentWords
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int letters [ ] = { 4 , 3 , 3 , 3 , 4 , 4 , 3 , 5 , 5 , 4 } ; static int sumOfLetters ( int n ) { int sum = 0 ; while ( n > 0 ) { sum += letters [ n % 10 ] ; n = n / 10 ; } return sum ; } static void sortArr ( int arr [ ] , int n ) { ArrayList < int [ ] > vp = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { vp . add ( new int [ ] { sumOfLetters ( arr [ i ] ) , arr [ i ] } ) ; } Collections . sort ( vp , ( a , b ) -> a [ 0 ] - b [ 0 ] ) ; for ( int i = 0 ; i < vp . size ( ) ; i ++ ) System . out . print ( vp . get ( i ) [ 1 ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 10 , 31 , 18 } ; int n = arr . length ; sortArr ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; static int block ; class Query { int L , R , index ; int armstrong ; Query ( int L , int R , int index , int armstrong ) { this . L = L ; this . R = R ; this . index = index ; this . armstrong = armstrong ; } } class GFG { static int count_Armstrong ; Arrays . sort ( q , ( Query x , Query y ) -> { if ( x . L / block != y . L / block ) return x . L / block - y . L / block ; return x . R - y . R ; } ) ; x . index - y . index ) ; for ( int i = 0 ; i < m ; i ++ ) { System . out . println ( q [ i ] . armstrong ) ; } } static boolean isArmstrong ( int x ) { int n = String . valueOf ( x ) . length ( ) ; int sum1 = 0 ; int temp = x ; while ( temp > 0 ) { int digit = temp % 10 ; sum1 += Math . pow ( digit , n ) ; temp /= 10 ; } if ( sum1 == x ) return true ; return false ; } static void add ( int currL , int a [ ] ) { if ( isArmstrong ( a [ currL ] ) ) count_Armstrong ++ ; } static void remove ( int currR , int a [ ] ) { if ( isArmstrong ( a [ currR ] ) ) count_Armstrong -- ; } static void queryResults ( int a [ ] , int n , Query q [ ] , int m ) { count_Armstrong = 0 ; block = ( int ) ( Math . sqrt ( n ) ) ; int currL = 0 , currR = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L , R = q [ i ] . R ; while ( currR <= R ) { add ( currR , a ) ; currR ++ ; } while ( currL > L ) { add ( currL - 1 , a ) ; currL -- ; } while ( currR > R + 1 ) { remove ( currR - 1 , a ) ; currR -- ; } while ( currL < L ) { remove ( currL , a ) ; currL ++ ; } q [ i ] . armstrong = count_Armstrong ; } } static void printResults ( Query q [ ] , int m ) { Arrays . sort ( q , ( Query x , Query y ) -> public static void main ( String [ ] args ) { int arr [ ] = { 18 , 153 , 8 , 9 , 14 , 5 } ; int n = arr . length ; Query q [ ] = new Query [ 2 ] ; q [ 0 ] = new Query ( 0 , 5 , 0 , 0 ) ; q [ 1 ] = new Query ( 3 , 5 , 1 , 0 ) ; int m = q . length ; queryResults ( arr , n , q , m ) ; printResults ( q , m ) ; } }

Index/key variables: currL, currR, i
Accumulator variables: count_Armstrong, currL, currR, i, sum1, temp
Iterator variables: i
Class/struct names: GFG, Query
Java program:
import java . util . * ; class GFG { static class node { int val ; node right , left ; } ; static node newnode ( int key ) { node temp = new node ( ) ; temp . val = key ; temp . right = null ; temp . left = null ; return temp ; } static void func ( node root ) { Queue < node > q = new LinkedList < > ( ) ; boolean t = true ; q . add ( root ) ; int i = - 1 , j = - 1 ; while ( ! q . isEmpty ( ) ) { int h = q . size ( ) ; while ( h > 0 ) { root = q . peek ( ) ; if ( i == - 1 ) { j = root . val ; } if ( i == - 2 ) { if ( j <= root . val ) { j = root . val ; i = - 3 ; } else { t = false ; break ; } } if ( root . left != null ) { q . add ( root . left ) ; } if ( root . right != null ) { q . add ( root . right ) ; } h = h - 1 ; q . remove ( ) ; } i = - 2 ; if ( t == false ) { break ; } } if ( t ) System . out . print ( " true " + "NEW_LINE"); else System . out . print ( " false " + "NEW_LINE"); } public static void main ( String [ ] args ) { node root = newnode ( 10 ) ; root . right = newnode ( 50 ) ; root . right . right = newnode ( 15 ) ; root . left = newnode ( 20 ) ; root . left . left = newnode ( 50 ) ; root . left . right = newnode ( 23 ) ; root . right . left = newnode ( 10 ) ; func ( root ) ; } }

Boolean variables: t
Class/struct names: GFG, node
Java program:
import java . util . * ; class GFG { static int calculate_minimum_split ( int n , int a [ ] , int k ) { Integer [ ] p = new Integer [ n - 1 ] ; for ( int i = 1 ; i < n ; i ++ ) p [ i - 1 ] = a [ i ] - a [ i - 1 ] ; Arrays . sort ( p , new Comparator < Integer > ( ) { public int compare ( Integer a , Integer b ) { return b - a ; } } ) ; int min_sum = 0 ; for ( int i = 0 ; i < k - 1 ; i ++ ) min_sum += p [ i ] ; int res = a [ n - 1 ] - a [ 0 ] - min_sum ; return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 8 , 15 , 16 , 23 , 42 } ; int k = 3 ; int n = arr . length ; System . out . println ( calculate_minimum_split ( n , arr , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, min_sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { if ( year2 . compareTo ( year1 ) > 0 ) return - 1 ; else if ( year2 . compareTo ( year1 ) < 0 ) return 1 ; else if ( month2 . compareTo ( month1 ) > 0 ) return - 1 ; else if ( month2 . compareTo ( month1 ) < 0 ) return 1 ; else if ( day2 . compareTo ( day1 ) > 0 ) return - 1 ; else return 1 ; } } ) ; static void printDatesAscending ( ArrayList < String > arr ) { Collections . sort ( arr , new Comparator < > ( ) { public int compare ( String date1 , String date2 ) { String day1 = date1 . substring ( 0 , 2 ) ; String month1 = date1 . substring ( 3 , 5 ) ; String year1 = date1 . substring ( 6 ) ; String day2 = date2 . substring ( 0 , 2 ) ; String month2 = date2 . substring ( 3 , 5 ) ; String year2 = date2 . substring ( 6 ) ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) System . out . println ( arr . get ( i ) ) ; } public static void main ( String [ ] args ) { ArrayList < String > arr = new ArrayList < > ( ) ; arr . add ( "25-08-1996" ) ; arr . add ( "03-08-1970" ) ; arr . add ( "09-04-1994" ) ; arr . add ( "29-08-1996" ) ; arr . add ( "14-02-1972" ) ; printDatesAscending ( arr ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static class pair { int first ; String second ; pair ( int first , String second ) { this . first = first ; this . second = second ; } } static boolean isVowel ( char ch ) { ch = Character . toUpperCase ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) ; } static int countVowels ( String str ) { int count = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) if ( isVowel ( str . charAt ( i ) ) ) ++ count ; return count ; } static void sortArr ( String arr [ ] , int n ) { ArrayList < pair > vp = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { vp . add ( new pair ( countVowels ( arr [ i ] ) , arr [ i ] ) ) ; } Collections . sort ( vp , ( a , b ) -> a . first - b . first ) ; for ( int i = 0 ; i < vp . size ( ) ; i ++ ) System . out . print ( vp . get ( i ) . second + " ▁ " ) ; } public static void main ( String [ ] args ) { String arr [ ] = { " lmno " , " pqrst " , " aeiou " , " xyz " } ; int n = arr . length ; sortArr ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static long minimumCost ( long price [ ] , int n ) { Arrays . sort ( price ) ; long totalCost = 0 ; for ( int i = n - 1 ; i > 1 ; i -= 2 ) { if ( i == 2 ) { totalCost += price [ 2 ] + price [ 0 ] ; } else { long price_first = price [ i ] + price [ 0 ] + 2 * price [ 1 ] ; long price_second = price [ i ] + price [ i - 1 ] + 2 * price [ 0 ] ; totalCost += Math . min ( price_first , price_second ) ; } } if ( n == 1 ) { totalCost += price [ 0 ] ; } else { totalCost += price [ 1 ] ; } return totalCost ; } public static void main ( String [ ] args ) { long price [ ] = { 30 , 40 , 60 , 70 } ; int n = price . length ; System . out . println ( minimumCost ( price , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, totalCost
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { final static int N = 100 ; final static int INF = 1000000 ; static int dp [ ] [ ] = new int [ N ] [ N ] ; static int vis [ ] [ ] = new int [ N ] [ N ] ; static int findSum ( int [ ] arr , int n , int k , int l , int r ) { if ( ( l ) + ( n - 1 - r ) == k ) return arr [ r ] - arr [ l ] ; if ( vis [ l ] [ r ] == 1 ) return dp [ l ] [ r ] ; vis [ l ] [ r ] = 1 ; dp [ l ] [ r ] = Math . min ( findSum ( arr , n , k , l , r - 1 ) , findSum ( arr , n , k , l + 1 , r ) ) ; return dp [ l ] [ r ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 100 , 120 , 140 } ; int k = 2 ; int n = arr . length ; System . out . println ( findSum ( arr , n , k , 0 , n - 1 ) ) ; } }

Index/key variables: N, l, r
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int getNumber ( int n , int k ) { int pos ; if ( ( n % 2 ) == 0 ) { pos = n / 2 ; } else { pos = ( n / 2 ) + 1 ; } if ( k <= pos ) { return ( k * 2 - 1 ) ; } else return ( ( k - pos ) * 2 ) ; } public static void main ( String [ ] args ) { int n = 8 , k = 5 ; System . out . println ( getNumber ( n , k ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void unique_combination ( int l , int sum , int K , Vector < Integer > local , Vector < Integer > A ) { if ( sum == K ) { System . out . print ( " { " ) ; for ( int i = 0 ; i < local . size ( ) ; i ++ ) { if ( i != 0 ) System . out . print ( " ▁ " ) ; System . out . print ( local . get ( i ) ) ; if ( i != local . size ( ) - 1 ) System . out . print ( " , ▁ " ) ; } System . out . println ( " } " ) ; return ; } for ( int i = l ; i < A . size ( ) ; i ++ ) { if ( sum + A . get ( i ) > K ) continue ; if ( i > l && A . get ( i ) == A . get ( i - 1 ) ) continue ; local . add ( A . get ( i ) ) ; unique_combination ( i + 1 , sum + A . get ( i ) , K , local , A ) ; local . remove ( local . size ( ) - 1 ) ; } } static void Combination ( Vector < Integer > A , int K ) { Collections . sort ( A ) ; Vector < Integer > local = new Vector < Integer > ( ) ; unique_combination ( 0 , 0 , K , local , A ) ; } public static void main ( String [ ] args ) { Integer [ ] arr = { 10 , 1 , 2 , 7 , 6 , 1 , 5 } ; Vector < Integer > A = new Vector < > ( Arrays . asList ( arr ) ) ; int K = 8 ; Combination ( A , K ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static int solution ( int arr [ ] , int x ) { int closestSum = Integer . MAX_VALUE ; for ( int i = 0 ; i < arr . length ; i ++ ) { for ( int j = i + 1 ; j < arr . length ; j ++ ) { for ( int k = j + 1 ; k < arr . length ; k ++ ) { if ( Math . abs ( x - closestSum ) > Math . abs ( x - ( arr [ i ] + arr [ j ] + arr [ k ] ) ) ) closestSum = ( arr [ i ] + arr [ j ] + arr [ k ] ) ; } } } return closestSum ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , 2 , 1 , - 4 } ; int x = 1 ; System . out . print ( solution ( arr , x ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void addEdge ( ArrayList < ArrayList < Integer > > adj , int u , int v ) { adj . get ( u ) . add ( v ) ; } static void getindeg ( ArrayList < ArrayList < Integer > > adj , int V , ArrayList < Integer > indeg ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int x : adj . get ( i ) ) { indeg . set ( x , indeg . get ( x ) + 1 ) ; } } } static ArrayList < Integer > topo ( ArrayList < ArrayList < Integer > > adj , int V , ArrayList < Integer > indeg ) { Queue < Integer > q = new LinkedList < > ( ) ; for ( int i = 0 ; i < V ; i ++ ) { if ( indeg . get ( i ) == 0 ) { q . add ( i ) ; } } ArrayList < Integer > res = new ArrayList < Integer > ( ) ; while ( q . size ( ) > 0 ) { int u = q . poll ( ) ; res . add ( u ) ; for ( int x : adj . get ( u ) ) { indeg . set ( x , indeg . get ( x ) - 1 ) ; if ( indeg . get ( x ) == 0 ) { q . add ( x ) ; } } } return res ; } static ArrayList < Integer > makearray ( ArrayList < ArrayList < Integer > > v , int V ) { ArrayList < ArrayList < Integer > > adj = new ArrayList < ArrayList < Integer > > ( ) ; for ( int i = 0 ; i < V ; i ++ ) { adj . add ( new ArrayList < Integer > ( ) ) ; } for ( int i = 0 ; i < v . size ( ) ; i ++ ) { for ( int j = 0 ; j < v . get ( i ) . size ( ) - 1 ; j ++ ) { addEdge ( adj , v . get ( i ) . get ( j ) , v . get ( i ) . get ( j + 1 ) ) ; } } ArrayList < Integer > indeg = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < V ; i ++ ) { indeg . add ( 0 ) ; } getindeg ( adj , V , indeg ) ; ArrayList < Integer > res = topo ( adj , V , indeg ) ; return res ; } public static void main ( String [ ] args ) { int n = 10 ; ArrayList < ArrayList < Integer > > subseqs = new ArrayList < ArrayList < Integer > > ( ) ; subseqs . add ( new ArrayList < Integer > ( Arrays . asList ( 9 , 1 , 2 , 8 , 3 ) ) ) ; subseqs . add ( new ArrayList < Integer > ( Arrays . asList ( 6 , 1 , 2 ) ) ) ; subseqs . add ( new ArrayList < Integer > ( Arrays . asList ( 9 , 6 , 3 , 4 ) ) ) ; subseqs . add ( new ArrayList < Integer > ( Arrays . asList ( 5 , 2 , 7 ) ) ) ; subseqs . add ( new ArrayList < Integer > ( Arrays . asList ( 0 , 9 , 5 , 4 ) ) ) ; ArrayList < Integer > res = makearray ( subseqs , n ) ; for ( int x : res ) { System . out . print ( x + " ▁ " ) ; } } }

Accumulator variables: i, j
Iterator variables: i, j, x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Vector < Long > pr = new Vector < > ( ) ; static boolean prime [ ] = new boolean [ 10000000 + 1 ] ; static void sieve ( long n ) { for ( int i = 2 ; i <= n ; i += 1 ) { prime [ i ] = true ; } for ( int p = 2 ; ( int ) p * ( int ) p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = ( int ) p * ( int ) p ; i <= n ; i += p ) prime [ i ] = false ; } } for ( int p = 2 ; p <= n ; p ++ ) if ( prime [ p ] ) pr . add ( ( long ) p ) ; } static long SemiPrimeSum ( long N ) { long ans = 0 ; for ( int i = 0 ; i < pr . size ( ) ; i += 1 ) { for ( int j = i ; j < pr . size ( ) ; j += 1 ) { if ( ( long ) pr . get ( i ) * ( long ) pr . get ( j ) > N ) break ; ans += ( long ) pr . get ( i ) * ( long ) pr . get ( j ) ; } } return ans ; } public static void main ( String [ ] args ) { long N = 6 ; sieve ( N ) ; System . out . println ( SemiPrimeSum ( N ) ) ; } }

Index/key variables: i, p
Accumulator variables: ans, i, j, p
Iterator variables: i, j, p
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static void compressArr ( int arr [ ] , int n ) { int i = 0 , j = 0 ; Arrays . sort ( arr ) ; while ( i < n ) { j = i ; while ( ( j + 1 < n ) && ( arr [ j + 1 ] == arr [ j ] + 1 ) ) { j ++ ; } if ( i == j ) { System . out . print ( arr [ i ] + " ▁ " ) ; i ++ ; } else { System . out . print ( arr [ i ] + " - " + arr [ j ] + " ▁ " ) ; i = j + 1 ; } } } public static void main ( String [ ] args ) { int n = 7 ; int arr [ ] = { 1 , 3 , 4 , 5 , 6 , 9 , 10 } ; compressArr ( arr , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void removeElements ( int [ ] arr , int n ) { int [ ] brr = new int [ n ] ; int l = 1 ; brr [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( brr [ l - 1 ] <= arr [ i ] ) { brr [ l ] = arr [ i ] ; l ++ ; } } for ( int i = 0 ; i < l ; i ++ ) System . out . print ( brr [ i ] + " ▁ " ) ; } static public void main ( String [ ] args ) { int [ ] arr = { 10 , 12 , 9 , 10 , 2 , 13 , 14 } ; int n = arr . length ; removeElements ( arr , n ) ; } }

Index/key variables: i, l, n
Accumulator variables: i, l
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findX ( int a [ ] , int n ) { Arrays . sort ( a ) ; int x = a [ 0 ] * a [ n - 1 ] ; Vector < Integer > vec = new Vector < Integer > ( ) ; for ( int i = 2 ; i * i <= x ; i ++ ) { if ( x % i == 0 ) { vec . add ( i ) ; if ( ( x / i ) != i ) vec . add ( x / i ) ; } } Collections . sort ( vec ) ; if ( vec . size ( ) != n ) return - 1 ; else { int i = 0 ; for ( int it : vec ) { if ( a [ i ++ ] != it ) return - 1 ; } } return x ; } public static void main ( String [ ] args ) { int a [ ] = { 2 , 5 , 4 , 10 } ; int n = a . length ; System . out . print ( findX ( a , n ) ) ; } }

Accumulator variables: i
Iterator variables: i, it
Class/struct names: GFG
Java program:
import java . util . Arrays ; import java . io . * ; class GFG { static void pendulumArrangement ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int odd , temp , in , pos ; pos = n - 1 ; if ( n % 2 == 0 ) odd = n - 1 ; else odd = n - 2 ; while ( odd > 0 ) { temp = arr [ odd ] ; in = odd ; while ( in != pos ) { arr [ in ] = arr [ in + 1 ] ; in ++ ; } arr [ in ] = temp ; odd = odd - 2 ; pos = pos - 1 ; } int start = 0 , end = ( n - 1 ) / 2 ; for ( ; start < end ; start ++ , end -- ) { temp = arr [ start ] ; arr [ start ] = arr [ end ] ; arr [ end ] = temp ; } for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 11 , 2 , 4 , 55 , 6 , 8 } ; int n = arr . length ; pendulumArrangement ( arr , n ) ; } }

Index/key variables: end, i, in, odd, start
Accumulator variables: end, i, in, start
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { public static class Node { int data ; Node left , right , root ; Node ( int data ) { this . data = data ; } } public static Node AddNode ( Node root , int data ) { if ( root == null ) { root = new Node ( data ) ; return root ; } if ( root . data < data ) root . right = AddNode ( root . right , data ) ; else if ( root . data > data ) root . left = AddNode ( root . left , data ) ; return root ; } public static void TargetPair ( Node node , int tar ) { ArrayList < Node > LeftList = new ArrayList < > ( ) ; ArrayList < Node > RightList = new ArrayList < > ( ) ; Node curr_left = node ; Node curr_right = node ; while ( curr_left != null || curr_right != null || LeftList . size ( ) > 0 && RightList . size ( ) > 0 ) { while ( curr_left != null ) { LeftList . add ( curr_left ) ; curr_left = curr_left . left ; } while ( curr_right != null ) { RightList . add ( curr_right ) ; curr_right = curr_right . right ; } Node LeftNode = LeftList . get ( LeftList . size ( ) - 1 ) ; Node RightNode = RightList . get ( RightList . size ( ) - 1 ) ; int leftVal = LeftNode . data ; int rightVal = RightNode . data ; if ( leftVal >= rightVal ) break ; if ( leftVal + rightVal < tar ) { LeftList . remove ( LeftList . size ( ) - 1 ) ; curr_left = LeftNode . right ; } else if ( leftVal + rightVal > tar ) { RightList . remove ( RightList . size ( ) - 1 ) ; curr_right = RightNode . left ; } else { System . out . println ( LeftNode . data + " ▁ " + RightNode . data ) ; RightList . remove ( RightList . size ( ) - 1 ) ; LeftList . remove ( LeftList . size ( ) - 1 ) ; curr_left = LeftNode . right ; curr_right = RightNode . left ; } } } public static void main ( String [ ] b ) { Node root = null ; root = AddNode ( root , 2 ) ; root = AddNode ( root , 6 ) ; root = AddNode ( root , 5 ) ; root = AddNode ( root , 3 ) ; root = AddNode ( root , 4 ) ; root = AddNode ( root , 1 ) ; root = AddNode ( root , 7 ) ; int sum = 8 ; TargetPair ( root , sum ) ; } }

Class/struct names: GFG, Node
Java program:
import java . util . Arrays ; class GFG { static int findNumber ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int max = arr [ n - 1 ] ; int table [ ] = new int [ ( 2 * max ) + 1 ] ; table [ 0 ] = 0 ; for ( int i = 1 ; i < ( 2 * max ) + 1 ; i ++ ) table [ i ] = Integer . MAX_VALUE ; int ans = - 1 ; for ( int i = 1 ; i < ( 2 * max ) + 1 ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( arr [ j ] <= i ) { int res = table [ i - arr [ j ] ] ; if ( res != Integer . MAX_VALUE && res + 1 < table [ i ] ) table [ i ] = res + 1 ; } } if ( i > arr [ n - 1 ] && table [ i ] == Integer . MAX_VALUE ) { ans = i ; break ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 7 , 15 } ; int n = arr . length ; System . out . println ( findNumber ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int MOD = 1000000007 ; static int max = 101 ; static long C [ ] [ ] = new long [ max ] [ max ] ; static long power ( long x , long y ) { long 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 % MOD ; } static void combi ( int n , int k ) { int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = ( C [ i - 1 ] [ j - 1 ] % MOD + C [ i - 1 ] [ j ] % MOD ) % MOD ; } } } static long product ( long a [ ] , int n , int k ) { long ans = 1 ; Arrays . sort ( a ) ; long powa = C [ n - 1 ] [ k - 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { long powla = C [ i ] [ k - 1 ] ; long powfa = C [ n - i - 1 ] [ k - 1 ] ; long powe = ( ( powa % MOD ) - ( powla + powfa ) % MOD + MOD ) % MOD ; long mul = power ( a [ i ] , powe ) % MOD ; ans = ( ( ans % MOD ) * ( mul % MOD ) ) % MOD ; } return ans % MOD ; } public static void main ( String [ ] args ) { combi ( 100 , 100 ) ; long arr [ ] = { 1 , 2 , 3 , 4 } ; int n = arr . length ; int k = 3 ; long ans = product ( arr , n , k ) ; System . out . println ( ans ) ; } }

Index/key variables: i, j, max
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countPoints ( int n , int m , int a [ ] , int [ ] b , int x , int y ) { Arrays . sort ( a ) ; Arrays . sort ( b ) ; int j = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { while ( j < m ) { if ( a [ i ] + y < b [ j ] ) break ; if ( b [ j ] >= a [ i ] - x && b [ j ] <= a [ i ] + y ) { count ++ ; j ++ ; break ; } else j ++ ; } } return count ; } public static void main ( String args [ ] ) { int x = 1 , y = 4 ; int [ ] a = { 1 , 5 } ; int n = a . length ; int [ ] b = { 1 , 1 , 2 } ; int m = a . length ; System . out . println ( countPoints ( n , m , a , b , x , y ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i
Class/struct names: GFG