dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { public static int maxEqualIdx ( int [ ] arr , int k ) { Arrays . sort ( arr ) ; int [ ] prefixSum = new int [ arr . length + 1 ] ; prefixSum [ 1 ] = arr [ 0 ] ; for ( int i = 1 ; i < prefixSum . length - 1 ; ++ i ) { prefixSum [ i + 1 ] = prefixSum [ i ] + arr [ i ] ; } int max = arr . length ; int min = 1 ; int ans = 1 ; while ( min <= max ) { int mid = ( max + min ) / 2 ; if ( check ( prefixSum , mid , k , arr ) ) { ans = mid ; min = mid + 1 ; } else { max = mid - 1 ; } } return ans ; } public static boolean check ( int [ ] pSum , int len , int k , int [ ] a ) { int i = 0 ; int j = len ; while ( j <= a . length ) { int maxSize = a [ j - 1 ] ; int totalNumbers = maxSize * len ; int currNumbers = pSum [ j ] - pSum [ i ] ; if ( currNumbers + k >= totalNumbers ) { return true ; } else { i ++ ; j ++ ; } } return false ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 1 } ; int k = 7 ; System . out . println ( maxEqualIdx ( arr , 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 productSum ( int [ ] arr ) { int cntOne = 0 ; int N = arr . length ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) cntOne ++ ; } return cntOne * ( cntOne - 1 ) / 2 ; } public static void main ( String [ ] args ) { int [ ] arr = { 0 , 1 , 1 , 0 , 1 } ; System . out . println ( productSum ( arr ) ) ; } }

Index/key variables: i
Accumulator variables: cntOne, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { static int minDigits ( int N , int K ) { int digits_num = ( int ) Math . floor ( Math . log ( N ) + 1 ) ; int temp_sum = 0 ; int temp = digits_num ; int result = 0 ; int X , var ; int sum = 0 ; int num2 = N ; while ( num2 != 0 ) { sum += num2 % 10 ; num2 /= 10 ; } if ( sum <= K ) { X = 0 ; } else { while ( temp > 0 ) { var = ( N / ( ( int ) Math . pow ( 10 , temp - 1 ) ) ) ; temp_sum += var % 10 ; if ( temp_sum >= K ) { var /= 10 ; var ++ ; result = var * ( int ) Math . pow ( 10 , temp ) ; break ; } temp -- ; } X = result - N ; return X ; } return - 1 ; } public static void main ( String args [ ] ) { int N = 11 ; int K = 1 ; System . out . println ( minDigits ( N , K ) ) ; } }

Accumulator variables: num2, sum, temp, temp_sum, var
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int findWays ( int [ ] nums , int S ) { int sum = 0 ; for ( int i = 0 ; i < nums . length ; i ++ ) sum += nums [ i ] ; int [ ] [ ] memo = new int [ nums . length + 1 ] [ 2 * sum + 1 ] ; for ( int [ ] m : memo ) { Arrays . fill ( m , Integer . MIN_VALUE ) ; } return dfs ( memo , nums , S , 0 , 0 , sum ) ; } static int dfs ( int [ ] [ ] memo , int [ ] nums , int S , int curr_sum , int index , int sum ) { if ( index == nums . length ) { if ( S == curr_sum ) return 1 ; else return 0 ; } if ( memo [ index ] [ curr_sum + sum ] != Integer . MIN_VALUE ) { return memo [ index ] [ curr_sum + sum ] ; } int ans = dfs ( memo , nums , index + 1 , curr_sum + nums [ index ] , S , sum ) + dfs ( memo , nums , index + 1 , curr_sum - nums [ index ] , S , sum ) ; memo [ index ] [ curr_sum + sum ] = ans ; return ans ; } public static void main ( String [ ] args ) { int S = 3 ; int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; int answer = findWays ( arr , S ) ; System . out . println ( answer ) ; } }

Index/key variables: i, index
Accumulator variables: i, sum
Iterator variables: i, m
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void max_length ( int N , int x , int [ ] v ) { int i , a ; List < Integer > preff = new Vector < Integer > ( ) ; List < Integer > suff = new Vector < Integer > ( ) ; int ct = 0 ; for ( i = 0 ; i < N ; i ++ ) { a = v [ i ] ; if ( a % x == 0 ) { ct += 1 ; } } if ( ct == N ) { System . out . print ( - 1 + "NEW_LINE"); return ; } v = reverse ( v ) ; suff . add ( v [ 0 ] ) ; for ( i = 1 ; i < N ; i ++ ) { suff . add ( v [ i ] + suff . get ( i - 1 ) ) ; } v = reverse ( v ) ; Collections . reverse ( suff ) ; preff . add ( v [ 0 ] ) ; for ( i = 1 ; i < N ; i ++ ) { preff . add ( v [ i ] + preff . get ( i - 1 ) ) ; } int ans = 0 ; int lp = 0 ; int rp = N - 1 ; for ( i = 0 ; i < N ; i ++ ) { if ( suff . get ( i ) % x != 0 && ( ans < ( N - 1 ) ) ) { lp = i ; rp = N - 1 ; ans = Math . max ( ans , N - i ) ; } if ( preff . get ( i ) % x != 0 && ( ans < ( i + 1 ) ) ) { lp = 0 ; rp = i ; ans = Math . max ( ans , i + 1 ) ; } } for ( i = lp ; i <= rp ; i ++ ) { System . out . print ( v [ i ] + " ▁ " ) ; } } static int [ ] reverse ( int a [ ] ) { int i , n = a . length , t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } public static void main ( String [ ] args ) { int x = 3 ; int [ ] v = { 1 , 3 , 2 , 6 } ; int N = v . length ; max_length ( N , x , v ) ; } }

Index/key variables: i
Accumulator variables: ct, i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static void maxUpdated ( int [ ] arr ) { int h_score = arr [ 0 ] ; int l_score = arr [ 0 ] ; int i = 1 , j = 1 ; for ( Integer n : arr ) { if ( h_score < n ) { h_score = n ; i ++ ; } if ( l_score > n ) { l_score = n ; j ++ ; } } System . out . print ( " Number ▁ of ▁ times ▁ maximum ▁ value ▁ " ) ; System . out . print ( " updated ▁ = ▁ " + i + "NEW_LINE"); System . out . print ( " Number ▁ of ▁ times ▁ minimum ▁ value ▁ " ) ; System . out . print ( " updated ▁ = ▁ " + j ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 10 , 5 , 20 , 22 } ; maxUpdated ( arr ) ; } }

Accumulator variables: i, j
Iterator variables: n
Class/struct names: GFG
Java program:
class GFG { static void farthest_min ( int [ ] a , int n ) { int [ ] suffix_min = new int [ n ] ; suffix_min [ n - 1 ] = a [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { suffix_min [ i ] = Math . min ( suffix_min [ i + 1 ] , a [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { int low = i + 1 , high = n - 1 , ans = - 1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( suffix_min [ mid ] < a [ i ] ) { ans = mid ; low = mid + 1 ; } else high = mid - 1 ; } System . out . print ( ans + " ▁ " ) ; } } public static void main ( String [ ] args ) { int [ ] a = { 3 , 1 , 5 , 2 , 4 } ; int n = a . length ; farthest_min ( a , n ) ; } }

Index/key variables: i, mid, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printElements ( int a [ ] , int n ) { Arrays . sort ( a ) ; a = reverse ( a ) ; int cnt = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] != a [ i + 1 ] ) { System . out . print ( a [ i ] + " ▁ occurs ▁ " + cnt + " timesNEW_LINE"); cnt = 1 ; } else cnt += 1 ; } System . out . print ( a [ n - 1 ] + " ▁ occurs ▁ " + cnt + " timesNEW_LINE"); } static int [ ] reverse ( int a [ ] ) { int i , n = a . length , t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 1 , 1 , 2 , 3 , 4 , 9 , 9 , 10 } ; int n = a . length ; printElements ( a , n ) ; } }

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static boolean checkSorted ( int n , int arr [ ] ) { int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) b [ i ] = arr [ i ] ; Arrays . sort ( b , 0 , n ) ; int ct = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] != b [ i ] ) ct ++ ; if ( ct == 0 ct == 2 ) return true ; else return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 3 , 4 , 2 } ; int n = arr . length ; if ( checkSorted ( n , arr ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, n
Accumulator variables: ct, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static boolean checkIndices ( int Arr [ ] , int N ) { for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( Arr [ i ] != Arr [ j ] ) { if ( Arr [ Arr [ i ] - 1 ] == Arr [ Arr [ j ] - 1 ] ) return true ; } } } return false ; } public static void main ( String args [ ] ) { int Arr [ ] = { 3 , 2 , 1 , 1 , 4 } ; int N = Arr . length ; if ( checkIndices ( Arr , N ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; class Pair { public int x , y ; Pair ( int x , int y ) { this . x = x ; this . y = y ; } } class GFG { public static void findPairs ( int [ ] A ) { Map < Integer , List < Pair > > map = new HashMap < > ( ) ; for ( int i = 0 ; i < A . length - 1 ; i ++ ) { for ( int j = i + 1 ; j < A . length ; j ++ ) { int sum = A [ i ] + A [ j ] ; if ( map . containsKey ( sum ) ) { for ( Pair pair : map . get ( sum ) ) { int x = pair . x ; int y = pair . y ; if ( ( x != i && x != j ) && ( y != i && y != j ) ) { System . out . println ( " Pair ▁ First ( " + A [ i ] + " , ▁ " + A [ j ] + " ) " ) ; System . out . println ( " Pair ▁ Second ▁ ( " + A [ x ] + " , ▁ " + A [ y ] + " ) " ) ; return ; } } } map . putIfAbsent ( sum , new ArrayList < > ( ) ) ; map . get ( sum ) . add ( new Pair ( i , j ) ) ; } } System . out . print ( " No ▁ such ▁ non - overlapping ▁ pairs ▁ present " ) ; } public static void main ( String [ ] args ) { int [ ] A = { 8 , 4 , 7 , 8 , 4 } ; findPairs ( A ) ; } }

Index/key variables: i, j, x, y
Accumulator variables: i, j
Iterator variables: i, j, pair
Class/struct names: GFG, Pair
Java program:
class GFG { static void printPairs ( int arr [ ] , int n , int sum ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] + arr [ j ] == sum ) System . out . println ( " ( " + arr [ i ] + " , ▁ " + arr [ j ] + " ) " ) ; } public static void main ( String [ ] arg ) { int arr [ ] = { 1 , 5 , 7 , - 1 , 5 } ; int n = arr . length ; int sum = 6 ; printPairs ( arr , n , sum ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countTripletsLessThanL ( int n , int L , int [ ] arr ) { Arrays . sort ( arr ) ; int ways = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int indexGreater = upper_bound ( arr , 0 , n , arr [ i ] + L ) ; int numberOfElements = indexGreater - ( i + 1 ) ; if ( numberOfElements >= 2 ) { ways += ( numberOfElements * ( numberOfElements - 1 ) / 2 ) ; } } return ways ; } static int upper_bound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = arr . length ; int L = 4 ; int ans = countTripletsLessThanL ( n , L , arr ) ; System . out . println ( " Total ▁ Number ▁ of ▁ ways ▁ = ▁ " + ans ) ; } }

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

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

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class RandomizedBinarySearch { public static int getRandom ( int x , int y ) { return ( x + ( int ) ( Math . random ( ) % ( y - x + 1 ) ) ) ; } public static int randomizedBinarySearch ( int arr [ ] , int low , int high , int key ) { if ( high >= low ) { int mid = getRandom ( low , high ) ; if ( arr [ mid ] == key ) return mid ; if ( arr [ mid ] > key ) return randomizedBinarySearch ( arr , low , mid - 1 , key ) ; return randomizedBinarySearch ( arr , mid + 1 , high , key ) ; } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 10 , 40 } ; int n = arr . length ; int key = 10 ; int result = randomizedBinarySearch ( arr , 0 , n - 1 , key ) ; System . out . println ( ( result == - 1 ) ? " Element ▁ is ▁ not ▁ present ▁ in ▁ array " : " Element ▁ is ▁ present ▁ at ▁ index ▁ " + result ) ; } }

Index/key variables: mid
Class/struct names: RandomizedBinarySearch
Java program:
import java . util . Arrays ; import java . util . List ; class Test { static String remVowel ( String str ) { Character vowels [ ] = { ' a ' , ' e ' , ' i ' , ' o ' , ' u ' , ' A ' , ' E ' , ' I ' , ' O ' , ' U ' } ; List < Character > al = Arrays . asList ( vowels ) ; StringBuffer sb = new StringBuffer ( str ) ; for ( int i = 0 ; i < sb . length ( ) ; i ++ ) { if ( al . contains ( sb . charAt ( i ) ) ) { sb . replace ( i , i + 1 , " " ) ; i -- ; } } return sb . toString ( ) ; } public static void main ( String [ ] args ) { String str = " GeeeksforGeeks ▁ - ▁ A ▁ Computer ▁ Science ▁ Portal ▁ for ▁ Geeks " ; System . out . println ( remVowel ( str ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: Test
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int minCostToMakeElementEqual ( int a [ ] , int n ) { int y ; if ( n % 2 == 1 ) y = a [ n / 2 ] ; else y = ( a [ n / 2 ] + a [ ( n - 2 ) / 2 ] ) / 2 ; int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) s += Math . abs ( a [ i ] - y ) ; return s ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 100 , 101 } ; int n = a . length ; System . out . println ( minCostToMakeElementEqual ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Class/struct names: GFG
Java program:
public static boolean isSorted ( int arr [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) return false ; } return true ; } public static boolean sortPoss ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { int idx = - 1 ; int minVar = arr [ i ] ; int j = i ; while ( j < n ) { if ( arr [ j ] < minVar ) { minVar = arr [ j ] ; idx = j ; } j = j + 2 ; } if ( idx != - 1 ) { int t ; t = arr [ i ] ; arr [ i ] = arr [ idx ] ; arr [ idx ] = t ; } } if ( isSorted ( arr , n ) ) return true ; else return false ; } public static void main ( String args [ ] ) { int arr [ ] = { 3 , 5 , 1 , 2 , 6 } ; int n = arr . length ; if ( sortPoss ( arr , n ) ) System . out . println ( " True " ) ; else System . out . println ( " False " ) ; } }

Index/key variables: i, idx, j
Accumulator variables: i
Iterator variables: i
Java program:
import java . util . * ; class GFG { static int upperBound ( int arr [ ] , int N , int K ) { int l = 0 ; int r = N ; while ( l < r ) { int mid = ( l + r ) / 2 ; if ( arr [ mid ] <= K ) { l = mid + 1 ; } else { r = mid ; } } return l ; } static void NDivKWithFreq ( int arr [ ] , int N , int K ) { Arrays . sort ( arr ) ; int i = 0 ; while ( i < N ) { int X = upperBound ( arr , N , arr [ i ] ) ; if ( ( X - i ) > N / 4 ) { System . out . print ( arr [ i ] + " ▁ " ) ; } i = X ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 2 , 6 , 6 , 6 , 6 , 7 , 10 } ; int N = arr . length ; int K = 4 ; NDivKWithFreq ( arr , N , K ) ; } }

Index/key variables: i, mid
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static long maxSum ( int [ ] a ) { int n = a . length ; int [ ] count = new int [ n + 1 ] ; for ( int x : a ) count [ Math . min ( x , n ) ] ++ ; int size = 0 ; long ans = 0 ; for ( int k = 1 ; k <= n ; k ++ ) { while ( count [ k ] > 0 && size < k ) { size ++ ; ans += size ; count [ k ] -- ; } ans += k * count [ k ] ; } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 5 , 1 } ; System . out . println ( maxSum ( arr ) ) ; } }

Index/key variables: k
Accumulator variables: ans, k, size
Iterator variables: k, x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void answerQueries ( int [ ] arr , int n , int [ ] [ ] queries ) { for ( int i = 0 ; i < queries . length ; i ++ ) { int ans = 0 ; int l = queries [ i ] [ 0 ] - 1 ; int r = queries [ i ] [ 1 ] - 1 ; Map < Integer , Integer > freq = new HashMap < > ( ) ; for ( int j = l ; j < r + 1 ; j ++ ) { freq . put ( arr [ j ] , freq . getOrDefault ( arr [ j ] , 0 ) + 1 ) ; } for ( int k : freq . keySet ( ) ) { ans += k * freq . get ( k ) ; } System . out . println ( ans ) ; } } public static void main ( String args [ ] ) { int [ ] arr = { 1 , 2 , 1 } ; int n = arr . length ; int [ ] [ ] queries = { { 1 , 2 } , { 1 , 3 } } ; answerQueries ( arr , n , queries ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static boolean PandigitalProduct_1_9 ( int n ) { for ( int i = 1 ; i * i <= n ; i ++ ) if ( n % i == 0 && isPandigital ( " " + n + i + n / i ) ) return true ; return false ; } public static boolean isPandigital ( String str ) { if ( str . length ( ) != 9 ) return false ; char ch [ ] = str . toCharArray ( ) ; Arrays . sort ( ch ) ; return new String ( ch ) . equals ( "123456789" ) ; } public static void main ( String [ ] args ) { int n = 6952 ; if ( PandigitalProduct_1_9 ( n ) == true ) System . out . println ( " yes " ) ; else System . out . println ( " no " ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static void printModeMedian ( int a [ ] , int n ) { int [ ] b = new int [ n ] ; int max = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ; int t = max + 1 ; int count [ ] = new int [ t ] ; for ( int i = 0 ; i < t ; i ++ ) { count [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { count [ a [ i ] ] ++ ; } int mode = 0 ; int k = count [ 0 ] ; for ( int i = 1 ; i < t ; i ++ ) { if ( count [ i ] > k ) { k = count [ i ] ; mode = i ; } } for ( int i = 1 ; i < t ; i ++ ) { count [ i ] = count [ i ] + count [ i - 1 ] ; } for ( int i = 0 ; i < n ; i ++ ) { b [ count [ a [ i ] ] - 1 ] = a [ i ] ; count [ a [ i ] ] -- ; } float median ; if ( n % 2 != 0 ) { median = b [ n / 2 ] ; } else { median = ( float ) ( ( b [ ( n - 1 ) / 2 ] + b [ ( n / 2 ) ] ) / 2.0 ) ; } System . out . println ( " median ▁ = ▁ " + median ) ; System . out . println ( " mode ▁ = ▁ " + mode ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 4 , 1 , 2 , 7 , 1 , 2 , 5 , 3 , 6 } ; int n = a . length ; printModeMedian ( a , n ) ; } }

Index/key variables: i, n, t
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GeeksforGeeks { final static int MAX = 26 ; static boolean function ( String str ) { int l = str . length ( ) ; int counter1 [ ] = new int [ MAX ] ; int counter2 [ ] = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { counter1 [ i ] = 0 ; counter2 [ i ] = 0 ; } for ( int i = 0 ; i < l / 2 ; i ++ ) counter1 [ str . charAt ( i ) - ' a ' ] ++ ; for ( int i = l / 2 ; i < l ; i ++ ) counter2 [ str . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( counter2 [ i ] != counter1 [ i ] ) return true ; } return false ; } public static void main ( String args [ ] ) { String str = " abcasdsabcae " ; if ( function ( str ) ) System . out . print ( " Yes , ▁ both ▁ halves ▁ " + " differ ▁ by ▁ at ▁ least ▁ one ▁ character " ) ; else System . out . print ( " No , ▁ both ▁ halves ▁ " + " do ▁ not ▁ differ ▁ at ▁ all " ) ; } }

Index/key variables: MAX, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GeeksforGeeks
Java program:
import java . util . * ; import java . lang . * ; class GeeksforGeeks { final static int MAX = 26 ; static boolean function ( String str ) { int l = str . length ( ) ; int counter [ ] = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) counter [ i ] = 0 ; for ( int i = 0 ; i < l / 2 ; i ++ ) counter [ str . charAt ( i ) - ' a ' ] ++ ; for ( int i = l / 2 ; i < l ; i ++ ) counter [ str . charAt ( i ) - ' a ' ] -- ; for ( int i = 0 ; i < MAX ; i ++ ) if ( counter [ i ] != 0 ) return true ; return false ; } public static void main ( String args [ ] ) { String str = " abcasdsabcae " ; if ( function ( str ) ) System . out . print ( " Yes , ▁ both ▁ halves " + " ▁ differ ▁ by ▁ at ▁ least ▁ one ▁ character " ) ; else System . out . print ( " No , ▁ both ▁ halves " + " ▁ do ▁ not ▁ differ ▁ at ▁ all " ) ; } }

Index/key variables: MAX, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GeeksforGeeks
Java program:
import java . util . Arrays ; import java . util . Comparator ; class Element { int index , no_of_fact ; public Element ( int i , int countFactors ) { index = i ; no_of_fact = countFactors ; } static int countFactors ( int n ) { int count = 0 ; int sq = ( int ) Math . sqrt ( n ) ; if ( sq * sq == n ) count ++ ; for ( int i = 1 ; i < Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) count += 2 ; } return count ; } static void printOnBasisOfFactors ( int arr [ ] , int n ) { Element num [ ] = new Element [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { num [ i ] = new Element ( i , countFactors ( arr [ i ] ) ) ; } Arrays . sort ( num , new Comparator < Element > ( ) { @ Override public int compare ( Element e1 , Element e2 ) { if ( e1 . no_of_fact == e2 . no_of_fact ) return e1 . index < e2 . index ? - 1 : 1 ; return e1 . no_of_fact > e2 . no_of_fact ? - 1 : 1 ; } } ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ num [ i ] . index ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 11 , 10 , 20 , 9 , 16 , 23 } ; printOnBasisOfFactors ( arr , arr . length ) ; } }

Index/key variables: i, n
Accumulator variables: count, i
Iterator variables: i
Class/struct names: Element
Java program:
import java . util . Arrays ; class GFG { static int minDifferenceAmongMaxMin ( int arr [ ] , int N , int K ) { Arrays . sort ( arr ) ; int res = 2147483647 ; for ( int i = 0 ; i <= ( N - K ) ; i ++ ) { int curSeqDiff = arr [ i + K - 1 ] - arr [ i ] ; res = Math . min ( res , curSeqDiff ) ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 20 , 30 , 100 , 101 , 102 } ; int N = arr . length ; int K = 3 ; System . out . print ( minDifferenceAmongMaxMin ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class ArrayIndex { static int getIndexInSortedArray ( int arr [ ] , int n , int idx ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ idx ] ) result ++ ; if ( arr [ i ] == arr [ idx ] && i < idx ) result ++ ; } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 3 , 5 , 2 , 3 , 4 , 3 , 1 , 5 } ; int n = arr . length ; int idxOfEle = 5 ; System . out . println ( getIndexInSortedArray ( arr , n , idxOfEle ) ) ; } }

Index/key variables: i, idx
Accumulator variables: i, result
Iterator variables: i
Class/struct names: ArrayIndex