dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; import java . lang . * ; public class GfG { public static void sort012 ( int arr [ ] , int n ) { int count0 = 0 , count1 = 0 ; int count2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) count0 ++ ; if ( arr [ i ] == 1 ) count1 ++ ; if ( arr [ i ] == 2 ) count2 ++ ; } for ( int i = 0 ; i < count0 ; i ++ ) arr [ i ] = 0 ; for ( int i = count0 ; i < ( count0 + count1 ) ; i ++ ) arr [ i ] = 1 ; for ( int i = ( count0 + count1 ) ; i < n ; i ++ ) arr [ i ] = 2 ; printArray ( arr , n ) ; } public static void printArray ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 } ; int n = 12 ; sort012 ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: count0, count1, count2, i
Iterator variables: i
Class/struct names: GfG
Java program:
import java . util . * ; import java . lang . * ; public class GfG { private final static int MAX = 100 ; public static String alternateSort ( String s1 ) { int n = s1 . length ( ) ; char [ ] s = s1 . toCharArray ( ) ; int [ ] lCount = new int [ MAX ] ; int [ ] uCount = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( Character . isUpperCase ( s [ i ] ) ) uCount [ s [ i ] - ' A ' ] ++ ; else lCount [ s [ i ] - ' a ' ] ++ ; } int i = 0 , j = 0 , k = 0 ; while ( k < n ) { while ( i < MAX && uCount [ i ] == 0 ) i ++ ; if ( i < MAX ) { s [ k ++ ] = ( char ) ( ' A ' + i ) ; uCount [ i ] -- ; } while ( j < MAX && lCount [ j ] == 0 ) j ++ ; if ( j < MAX ) { s [ k ++ ] = ( char ) ( ' a ' + j ) ; lCount [ j ] -- ; } } return ( new String ( s ) ) ; } public static void main ( String argc [ ] ) { String str = " bAwutndekWEdkd " ; System . out . println ( alternateSort ( str ) ) ; } }

Index/key variables: MAX, i, j
Accumulator variables: i, j, k
Iterator variables: i
Class/struct names: GfG
Java program:
import java . util . * ; class GFG { static void optimum_sequence_jobs ( int [ ] V , double P ) { int j = 1 , N = V . length - 1 ; double result = 0 ; PriorityQueue < Integer > Queue = new PriorityQueue < > ( ) ; for ( int i = 1 ; i <= N ; i ++ ) Queue . add ( V [ i ] ) ; while ( ! Queue . isEmpty ( ) ) { System . out . print ( Queue . peek ( ) + " ▁ " ) ; V [ j ++ ] = Queue . peek ( ) ; Queue . remove ( ) ; } for ( int i = N ; i >= 1 ; i -- ) result += Math . pow ( ( 1 - P ) , N - i ) * V [ i ] ; System . out . printf ( " % .2f ", result ); } public static void main ( String [ ] args ) { int [ ] V = { - 1 , 3 , 5 , 4 , 1 , 2 , 7 , 6 , 8 , 9 , 10 } ; double P = 0.10 ; optimum_sequence_jobs ( V , P ) ; } }

Index/key variables: i
Accumulator variables: i, j, result
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int distancesum ( int x [ ] , int y [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) sum += ( Math . abs ( x [ i ] - x [ j ] ) + Math . abs ( y [ i ] - y [ j ] ) ) ; return sum ; } public static void main ( String [ ] args ) { int x [ ] = { - 1 , 1 , 3 , 2 } ; int y [ ] = { 5 , 6 , 5 , 3 } ; int n = x . length ; System . out . println ( distancesum ( x , y , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int distancesum ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int res = 0 , sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { res += ( arr [ i ] * i - sum ) ; sum += arr [ i ] ; } return res ; } static int totaldistancesum ( int x [ ] , int y [ ] , int n ) { return distancesum ( x , n ) + distancesum ( y , n ) ; } public static void main ( String [ ] args ) { int x [ ] = { - 1 , 1 , 3 , 2 } ; int y [ ] = { 5 , 6 , 5 , 3 } ; int n = x . length ; System . out . println ( totaldistancesum ( x , y , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, res, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void sortRec ( int arr [ ] , int index , int k , int n ) { if ( k == 0 ) { for ( int i = 1 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( 999 ) ; return ; } else if ( k > 0 && index == 0 ) { index = n - 2 ; for ( int i = 1 ; i <= index ; i ++ ) { arr [ i - 1 ] = arr [ i ] ; } arr [ index ] = 999 ; } if ( index - 1 >= 0 && index + 1 < n && arr [ index - 1 ] > arr [ index + 1 ] ) { swap ( arr , index , index + 1 ) ; swap ( arr , index - 1 , index + 1 ) ; } else swap ( arr , index , index - 1 ) ; sortRec ( arr , index - 1 , k - 1 , n ) ; } static int [ ] swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } static void sort ( int arr [ ] , int n ) { int index = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 999 ) { index = i ; break ; } } if ( index == - 1 ) return ; sortRec ( arr , index , n , n ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 999 , 1 } ; int n = arr . length ; sort ( arr , n ) ; } }

Index/key variables: i, index, j
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void unsort ( int l , int r , int a [ ] , int k ) { if ( k < 1 l + 1 == r ) return ; k -= 2 ; int mid = ( l + r ) / 2 ; int temp = a [ mid - 1 ] ; a [ mid - 1 ] = a [ mid ] ; a [ mid ] = temp ; unsort ( l , mid , a , k ) ; unsort ( mid , r , a , k ) ; } static void arrayWithKCalls ( int n , int k ) { if ( k % 2 == 0 ) { System . out . print ( " NO ▁ SOLUTION " ) ; return ; } int a [ ] = new int [ n + 1 ] ; a [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) a [ i ] = i + 1 ; k -- ; unsort ( 0 , n , a , k ) ; for ( int i = 0 ; i < n ; ++ i ) System . out . print ( a [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 10 , k = 17 ; arrayWithKCalls ( n , k ) ; } }

Index/key variables: i, mid
Accumulator variables: i, k
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int MAX_CHAR = 26 ; static void sortString ( String str ) { int charCount [ ] = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { charCount [ str . charAt ( i ) - ' a ' ] ++ ; } for ( int i = MAX_CHAR - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < charCount [ i ] ; j ++ ) { System . out . print ( ( char ) ( ' a ' + i ) ) ; } } } public static void main ( String [ ] args ) { String s = " alkasingh " ; sortString ( s ) ; } }

Index/key variables: MAX_CHAR, i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static void printMedian ( int arr [ ] , int n , int K ) { Arrays . sort ( arr ) ; System . out . print ( arr [ ( n + K ) / 2 ] ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 3 , 2 , 8 } ; int k = 3 ; int n = arr . length ; printMedian ( arr , n , k ) ; } }

Class/struct names: GFG
Java program:
class GFG { static void swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } static void dualPivotQuickSort ( int [ ] arr , int low , int high ) { if ( low < high ) { int [ ] piv ; piv = partition ( arr , low , high ) ; dualPivotQuickSort ( arr , low , piv [ 0 ] - 1 ) ; dualPivotQuickSort ( arr , piv [ 0 ] + 1 , piv [ 1 ] - 1 ) ; dualPivotQuickSort ( arr , piv [ 1 ] + 1 , high ) ; } } static int [ ] partition ( int [ ] arr , int low , int high ) { if ( arr [ low ] > arr [ high ] ) swap ( arr , low , high ) ; int j = low + 1 ; int g = high - 1 , k = low + 1 , p = arr [ low ] , q = arr [ high ] ; while ( k <= g ) { if ( arr [ k ] < p ) { swap ( arr , k , j ) ; j ++ ; } else if ( arr [ k ] >= q ) { while ( arr [ g ] > q && k < g ) g -- ; swap ( arr , k , g ) ; g -- ; if ( arr [ k ] < p ) { swap ( arr , k , j ) ; j ++ ; } } k ++ ; } j -- ; g ++ ; swap ( arr , low , j ) ; swap ( arr , high , g ) ; return new int [ ] { j , g } ; } public static void main ( String [ ] args ) { int [ ] arr = { 24 , 8 , 42 , 75 , 29 , 77 , 38 , 57 } ; dualPivotQuickSort ( arr , 0 , 7 ) ; System . out . print ( " Sorted ▁ array : ▁ " ) ; for ( int i = 0 ; i < 8 ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( ) ; } }

Index/key variables: g, high, i, j, k, low
Accumulator variables: g, i, j, k
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void minMaxSelectionSort ( int [ ] arr , int n ) { for ( int i = 0 , j = n - 1 ; i < j ; i ++ , j -- ) { int min = arr [ i ] , max = arr [ i ] ; int min_i = i , max_i = i ; for ( int k = i ; k <= j ; k ++ ) { if ( arr [ k ] > max ) { max = arr [ k ] ; max_i = k ; } else if ( arr [ k ] < min ) { min = arr [ k ] ; min_i = k ; } } swap ( arr , i , min_i ) ; if ( arr [ min_i ] == max ) swap ( arr , j , min_i ) ; else swap ( arr , j , max_i ) ; } } static int [ ] swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } public static void main ( String [ ] args ) { int arr [ ] = { 23 , 78 , 45 , 8 , 32 , 56 , 1 } ; int n = arr . length ; minMaxSelectionSort ( arr , n ) ; System . out . printf ( "Sorted array:NEW_LINE"); for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( " " ) ; } }

Index/key variables: i, j, k, min_i
Accumulator variables: i, j, k
Iterator variables: i, k
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void mergeArray ( int a [ ] , int b [ ] , int n , int m ) { int mx = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mx = Math . max ( mx , a [ i ] ) ; } for ( int i = 0 ; i < m ; i ++ ) { mx = Math . max ( mx , b [ i ] ) ; } mx ++ ; int i = 0 , j = 0 , k = 0 ; while ( i < n && j < m && k < ( n + m ) ) { int e1 = a [ i ] % mx ; int e2 = b [ j ] % mx ; if ( e1 <= e2 ) { if ( k < n ) a [ k ] += ( e1 * mx ) ; else b [ k - n ] += ( e1 * mx ) ; i ++ ; k ++ ; } else { if ( k < n ) a [ k ] += ( e2 * mx ) ; else b [ k - n ] += ( e2 * mx ) ; j ++ ; k ++ ; } } while ( i < n ) { int el = a [ i ] % mx ; if ( k < n ) a [ k ] += ( el * mx ) ; else b [ k - n ] += ( el * mx ) ; i ++ ; k ++ ; } while ( j < m ) { int el = b [ j ] % mx ; if ( k < n ) b [ k ] += ( el * mx ) ; else b [ k - n ] += ( el * mx ) ; j ++ ; k ++ ; } for ( int in = 0 ; in < n ; in ++ ) a [ in ] = a [ in ] / mx ; for ( int in = 0 ; in < m ; in ++ ) b [ in ] = b [ in ] / mx ; return ; } public static void main ( String [ ] args ) { int a [ ] = { 3 , 5 , 6 , 8 , 12 } ; int b [ ] = { 1 , 4 , 9 , 13 } ; int n = a . length ; int m = b . length ; mergeArray ( a , b , n , m ) ; System . out . print ( " First ▁ array ▁ : ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( a [ i ] + " ▁ " ) ; System . out . println ( ) ; System . out . print ( " Second ▁ array ▁ : ▁ " ) ; for ( int i = 0 ; i < m ; i ++ ) System . out . print ( b [ i ] + " ▁ " ) ; System . out . println ( ) ; } }

Index/key variables: i, in, j, k
Accumulator variables: i, in, j, k, mx
Iterator variables: i, in
Class/struct names: GFG
Java program:
class GFG { static void arrange ( int arr [ ] , int n , int x ) { for ( int i = 1 ; i < n ; i ++ ) { int diff = Math . abs ( arr [ i ] - x ) ; int j = i - 1 ; if ( Math . abs ( arr [ j ] - x ) > diff ) { int temp = arr [ i ] ; while ( j >= 0 && Math . abs ( arr [ j ] - x ) > diff ) { arr [ j + 1 ] = arr [ j ] ; j -- ; } arr [ j + 1 ] = temp ; } } } static void print ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 5 , 3 , 9 , 2 } ; int n = arr . length ; int x = 7 ; arrange ( arr , n , x ) ; print ( arr , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GfG { static boolean check ( String [ ] v , int len ) { int n = v . length ; char [ ] tempArray ; for ( int i = 0 ; i < n ; i ++ ) { tempArray = v [ i ] . toCharArray ( ) ; Arrays . sort ( tempArray ) ; v [ i ] = new String ( tempArray ) ; } for ( int i = 0 ; i < len - 1 ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( v [ i ] . charAt ( j ) > v [ i + 1 ] . charAt ( j ) ) return false ; return true ; } public static void main ( String [ ] args ) { String [ ] v = { " ebcda " , " ihgfj " , " klmno " , " pqrst " , " yvwxu " } ; if ( check ( v , len ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GfG
Java program:
import java . util . * ; class GFG { static void printOrder ( int [ ] arr , int n ) { Arrays . sort ( arr ) ; for ( int i = 0 ; i < n / 2 ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } for ( int j = n - 1 ; j >= n / 2 ; j -- ) { System . out . print ( arr [ j ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 5 , 4 , 6 , 2 , 1 , 3 , 8 , - 1 } ; int n = arr . length ; printOrder ( arr , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static class Pair { int first , second ; public Pair ( int first , int second ) { this . first = first ; this . second = second ; } } static Pair findSubArray ( int arr [ ] , int n ) { int start = 0 , end = 0 , min_sum = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int curr_sum = arr [ i ] ; if ( min_sum > Math . abs ( curr_sum ) ) { min_sum = Math . abs ( curr_sum ) ; start = i ; end = i ; } for ( int j = i + 1 ; j < n ; j ++ ) { curr_sum = curr_sum + arr [ j ] ; if ( min_sum > Math . abs ( curr_sum ) ) { min_sum = Math . abs ( curr_sum ) ; start = i ; end = j ; } } } Pair p = new Pair ( start , end ) ; return p ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , - 5 , 4 , - 6 , - 3 } ; int n = arr . length ; Pair point = findSubArray ( arr , n ) ; System . out . println ( " Subarray ▁ starting ▁ from ▁ " + point . first + " ▁ to ▁ " + point . second ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, Pair
Java program:
import java . io . * ; import java . util . * ; class GFG { public String [ ] uniquePrefix ( String [ ] a ) { int size = a . length ; String [ ] res = new String [ size ] ; Arrays . sort ( a ) ; int j = 0 ; while ( j < Math . min ( a [ 0 ] . length ( ) - 1 , a [ 1 ] . length ( ) - 1 ) ) { if ( a [ 0 ] . charAt ( j ) == a [ 1 ] . charAt ( j ) ) j ++ ; else break ; } int ind = 0 ; res [ ind ++ ] = a [ 0 ] . substring ( 0 , j + 1 ) ; String temp_prefix = a [ 1 ] . substring ( 0 , j + 1 ) ; for ( int i = 1 ; i < size - 1 ; i ++ ) { j = 0 ; while ( j < Math . min ( a [ i ] . length ( ) - 1 , a [ i + 1 ] . length ( ) - 1 ) ) { if ( a [ i ] . charAt ( j ) == a [ i + 1 ] . charAt ( j ) ) j ++ ; else break ; } String new_prefix = a [ i ] . substring ( 0 , j + 1 ) ; if ( temp_prefix . length ( ) > new_prefix . length ( ) ) res [ ind ++ ] = temp_prefix ; else res [ ind ++ ] = new_prefix ; temp_prefix = a [ i + 1 ] . substring ( 0 , j + 1 ) ; } j = 0 ; String sec_last = a [ size - 2 ] ; String last = a [ size - 1 ] ; while ( j < Math . min ( sec_last . length ( ) - 1 , last . length ( ) - 1 ) ) { if ( sec_last . charAt ( j ) == last . charAt ( j ) ) j ++ ; else break ; } res [ ind ] = last . substring ( 0 , j + 1 ) ; return res ; } public static void main ( String [ ] args ) { GFG gfg = new GFG ( ) ; String [ ] input = { " zebra " , " dog " , " duck " , " dove " } ; String [ ] output = gfg . uniquePrefix ( input ) ; System . out . println ( " The ▁ shortest ▁ unique ▁ prefixes " + " ▁ in ▁ sorted ▁ order ▁ are ▁ : " ) ; for ( int i = 0 ; i < output . length ; i ++ ) System . out . print ( output [ i ] + " ▁ " ) ; } }

Index/key variables: i, ind, size
Accumulator variables: i, ind, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findMinimum ( int arr [ ] , int n , int k ) { int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { res += arr [ i ] ; n = n - k ; } return res ; } static int findMaximum ( int arr [ ] , int n , int k ) { int res = 0 , index = 0 ; for ( int i = n - 1 ; i >= index ; i -- ) { res += arr [ i ] ; index += k ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 1 , 4 } ; int n = arr . length ; int k = 2 ; Arrays . sort ( arr ) ; System . out . println ( findMinimum ( arr , n , k ) + " ▁ " + findMaximum ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, index, res
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void mergeArrays ( int a [ ] , int b [ ] , int n , int m ) { Map < Integer , Boolean > mp = new HashMap < Integer , Boolean > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mp . put ( a [ i ] , true ) ; } for ( int i = 0 ; i < m ; i ++ ) { mp . put ( b [ i ] , true ) ; } for ( Map . Entry < Integer , Boolean > me : mp . entrySet ( ) ) { System . out . print ( me . getKey ( ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 5 , 7 } , b [ ] = { 2 , 4 , 6 , 8 } ; int size = a . length ; int size1 = b . length ; mergeArrays ( a , b , size , size1 ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void printInSortedOrder ( String arr [ ] , int n ) { int index [ ] = new int [ n ] ; int i , j , min ; for ( i = 0 ; i < n ; i ++ ) { index [ i ] = i ; } for ( i = 0 ; i < n - 1 ; i ++ ) { min = i ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ index [ min ] ] . compareTo ( arr [ index [ j ] ] ) > 0 ) { min = j ; } } if ( min != i ) { int temp = index [ min ] ; index [ min ] = index [ i ] ; index [ i ] = temp ; } } for ( i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ index [ i ] ] + " ▁ " ) ; } } static public void main ( String [ ] args ) { String arr [ ] = { " geeks " , " quiz " , " geeks " , " for " } ; int n = 4 ; printInSortedOrder ( arr , n ) ; } }

Index/key variables: i, j, min, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . Arrays ; class GFG { static int maxLevel ( int [ ] boxes , int n ) { Arrays . sort ( boxes ) ; int prev_width = boxes [ 0 ] ; int prev_count = 1 ; int curr_count = 0 ; int curr_width = 0 ; for ( int i = 1 ; i < n ; i ++ ) { curr_width += boxes [ i ] ; curr_count += 1 ; if ( curr_width > prev_width && curr_count > prev_count ) { prev_width = curr_width ; prev_count = curr_count ; curr_count = 0 ; curr_width = 0 ; ans ++ ; } } return ans ; } static public void main ( String [ ] args ) { int [ ] boxes = { 10 , 20 , 30 , 50 , 60 , 70 } ; int n = boxes . length ; System . out . println ( maxLevel ( boxes , n ) ) ; } }

Index/key variables: i
Accumulator variables: ans, curr_count, curr_width, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX_SIZE = 10 ; static void sortArrayUsingCounts ( int arr [ ] , int n ) { int [ ] count = new int [ MAX_SIZE ] ; for ( int i = 0 ; i < n ; i ++ ) { count [ arr [ i ] ] ++ ; } int index = 0 ; for ( int i = 0 ; i < MAX_SIZE ; i ++ ) { while ( count [ i ] > 0 ) { arr [ index ++ ] = i ; count [ i ] -- ; } } } static void removeAndPrintResult ( int arr [ ] , int n , int ind1 , int ind2 ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( i != ind1 && i != ind2 ) { System . out . print ( arr [ i ] ) ; } } } static boolean largest3Multiple ( int arr [ ] , int n ) { int sum = accumulate ( arr , 0 , n ) ; if ( sum % 3 == 0 ) { return true ; } sortArrayUsingCounts ( arr , n ) ; int remainder = sum % 3 ; if ( remainder == 1 ) { int [ ] rem_2 = new int [ 2 ] ; rem_2 [ 0 ] = - 1 ; rem_2 [ 1 ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 3 == 1 ) { removeAndPrintResult ( arr , n , i , - 1 ) ; return true ; } if ( arr [ i ] % 3 == 2 ) { if ( rem_2 [ 0 ] == - 1 ) { rem_2 [ 0 ] = i ; } else if ( rem_2 [ 1 ] == - 1 ) { rem_2 [ 1 ] = i ; } } } if ( rem_2 [ 0 ] != - 1 && rem_2 [ 1 ] != - 1 ) { removeAndPrintResult ( arr , n , rem_2 [ 0 ] , rem_2 [ 1 ] ) ; return true ; } } else if ( remainder == 2 ) { int [ ] rem_1 = new int [ 2 ] ; rem_1 [ 0 ] = - 1 ; rem_1 [ 1 ] = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 3 == 2 ) { removeAndPrintResult ( arr , n , i , - 1 ) ; return true ; } if ( arr [ i ] % 3 == 1 ) { if ( rem_1 [ 0 ] == - 1 ) { rem_1 [ 0 ] = i ; } else if ( rem_1 [ 1 ] == - 1 ) { rem_1 [ 1 ] = i ; } } } if ( rem_1 [ 0 ] != - 1 && rem_1 [ 1 ] != - 1 ) { removeAndPrintResult ( arr , n , rem_1 [ 0 ] , rem_1 [ 1 ] ) ; return true ; } } System . out . print ( " Not ▁ possible " ) ; return false ; } static int accumulate ( int [ ] arr , int start , int end ) { int sum = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { sum += arr [ i ] ; } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 4 , 1 , 1 , 1 , 3 } ; int n = arr . length ; largest3Multiple ( arr , n ) ; } }

Index/key variables: MAX_SIZE, i
Accumulator variables: i, index, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int merge ( int arr [ ] , int temp [ ] , int left , int mid , int right ) { int inv_count = 0 ; int i = left ; int j = mid ; int k = left ; while ( ( i <= mid - 1 ) && ( j <= right ) ) { if ( arr [ i ] <= arr [ j ] ) { temp [ k ++ ] = arr [ i ++ ] ; } else { temp [ k ++ ] = arr [ j ++ ] ; inv_count = inv_count + ( mid - i ) ; } } while ( i <= mid - 1 ) { temp [ k ++ ] = arr [ i ++ ] ; } while ( j <= right ) { temp [ k ++ ] = arr [ j ++ ] ; } for ( i = left ; i <= right ; i ++ ) { arr [ i ] = temp [ i ] ; } return inv_count ; } static int _mergeSort ( int arr [ ] , int temp [ ] , int left , int right ) { int mid , inv_count = 0 ; if ( right > left ) { mid = ( right + left ) / 2 ; inv_count = _mergeSort ( arr , temp , left , mid ) ; inv_count += _mergeSort ( arr , temp , mid + 1 , right ) ; inv_count += merge ( arr , temp , left , mid + 1 , right ) ; } return inv_count ; } static int mergeSort ( int arr [ ] , int array_size ) { int [ ] temp = new int [ array_size ] ; return _mergeSort ( arr , temp , 0 , array_size - 1 ) ; } static int minSwapToReachArr ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] - 1 ) - i > 2 ) { return - 1 ; } } int numOfInversion = mergeSort ( arr , N ) ; return numOfInversion ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 5 , 3 , 4 } ; int N = arr . length ; int res = minSwapToReachArr ( arr , N ) ; System . out . println ( res == - 1 ? "Not PossibleNEW_LINE" : res); } }

Index/key variables: array_size, i, j
Accumulator variables: i, inv_count, j, k
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; public class GFG { static void twoWaySort ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) arr [ i ] *= - 1 ; Arrays . sort ( arr ) ; for ( int i = 0 ; i < n ; i ++ ) if ( ( arr [ i ] & 1 ) != 0 ) arr [ i ] *= - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 2 , 7 , 5 , 4 } ; twoWaySort ( arr , arr . length ) ; System . out . println ( Arrays . toString ( arr ) ) ; } }

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