dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; class GFG { public static int maximumSum ( int [ ] a , int [ ] b , int n , int index , int lastpicked ) { if ( index == n ) return 0 ; int option1 = 0 , option2 = 0 ; if ( lastpicked == - 1 a [ lastpicked ] != a [ index ] ) option1 = b [ index ] + maximumSum ( a , b , n , index + 1 , index ) ; option2 = maximumSum ( a , b , n , index + 1 , lastpicked ) ; return Math . max ( option1 , option2 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 3 , 3 , 1 } ; int brr [ ] = { - 1 , 2 , 10 , 20 , - 10 , - 9 } ; int N = arr . length ; System . out . println ( maximumSum ( arr , brr , N , 0 , - 1 ) ) ; } }

Index/key variables: index, lastpicked
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void sumOfKElements ( int arr [ ] , int n , int k ) { boolean rev = false ; if ( k < 0 ) { rev = true ; k *= - 1 ; int l = 0 , r = n - 1 ; while ( l < r ) { int tmp = arr [ l ] ; arr [ l ] = arr [ r ] ; arr [ r ] = tmp ; l ++ ; r -- ; } } int dp [ ] = new int [ n ] ; dp [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] += dp [ i - 1 ] + arr [ i ] ; } int ans [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( i + k < n ) ans [ i ] = dp [ i + k ] - dp [ i ] ; else { int x = k - ( n - 1 - i ) ; int y = x / n ; int rem = x % n ; ans [ i ] = dp [ n - 1 ] - dp [ i ] + y * dp [ n - 1 ] + ( rem - 1 >= 0 ? dp [ rem - 1 ] : 0 ) ; } } if ( rev ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { System . out . print ( ans [ i ] + " ▁ " ) ; } } else { for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( ans [ i ] + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 2 , - 5 , 11 } ; int N = arr . length ; int K = 3 ; sumOfKElements ( arr , N , K ) ; } }

Index/key variables: i, l, n, r
Accumulator variables: i, k, l, r
Iterator variables: i
Boolean variables: rev
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int binaryInsert ( ArrayList < Integer > boundary , int i ) { int l = 0 ; int r = boundary . size ( ) - 1 ; while ( l <= r ) { int m = ( l + r ) / 2 ; if ( boundary . get ( m ) < i ) l = m + 1 ; else r = m - 1 ; } boundary . add ( l , i ) ; return l ; } static int [ ] countingSubarray ( int [ ] arr , int n ) { Map < Integer , Integer > index = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) index . put ( arr [ i ] , i ) ; ArrayList < Integer > boundary = new ArrayList < > ( ) ; boundary . add ( - 1 ) ; boundary . add ( n ) ; Arrays . sort ( arr ) ; int [ ] ans = new int [ n ] ; for ( int num : arr ) { int i = binaryInsert ( boundary , index . get ( num ) ) ; int l = boundary . get ( i ) - boundary . get ( i - 1 ) - 1 ; int r = boundary . get ( i + 1 ) - boundary . get ( i ) - 1 ; int cnt = l + r + l * r + 1 ; ans [ index . get ( num ) ] += cnt ; } return ans ; } public static void main ( String [ ] args ) { int N = 5 ; int [ ] arr = { 3 , 2 , 4 , 1 , 5 } ; int [ ] a = countingSubarray ( arr , N ) ; System . out . print ( " [ " ) ; int n = a . length - 1 ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( a [ i ] + " , ▁ " ) ; System . out . print ( a [ n ] + " ] " ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i, num
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int limit = 1000000000 ; static int F ( int N ) { String str = String . valueOf ( N ) ; int sum = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { int val = ( int ) ( str . charAt ( i ) - '0' ) ; sum += val * val * val ; } return sum ; } static int findDestination ( int N ) { HashSet < Integer > s = new HashSet < > ( ) ; int prev = N , next = 0 ; s . add ( N ) ; while ( N <= limit ) { next = F ( N ) ; if ( s . contains ( next ) ) { return next ; } prev = next ; s . add ( prev ) ; N = next ; } return next ; } static void digitCubeLimit ( int N ) { if ( N < 0 ) System . out . print ( "N cannot be negativeNEW_LINE"); else { int ans = findDestination ( N ) ; if ( ans > limit ) System . out . print ( "Limit exceededNEW_LINE"); else if ( ans == F ( ans ) ) { System . out . print ( N ) ; System . out . print ( " ▁ reaches ▁ to ▁ a " + " ▁ fixed ▁ point : ▁ " ) ; System . out . print ( ans ) ; } else { System . out . print ( N ) ; System . out . print ( " ▁ reaches ▁ to ▁ a " + " ▁ limit ▁ cycle : ▁ " ) ; System . out . print ( ans ) ; } } } public static void main ( String [ ] args ) { int N = 3 ; digitCubeLimit ( N ) ; } }

Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countTuples ( int arr [ ] , int N ) { int ans = 0 , val = 0 ; HashMap < Integer , Integer > freq = new HashMap < Integer , Integer > ( ) ; for ( int j = 0 ; j < N - 2 ; j ++ ) { val = 0 ; for ( int l = j + 1 ; l < N ; l ++ ) { if ( arr [ j ] == arr [ l ] ) { ans += val ; } if ( freq . containsKey ( arr [ l ] ) ) val += freq . get ( arr [ l ] ) ; } if ( freq . containsKey ( arr [ j ] ) ) { freq . put ( arr [ j ] , freq . get ( arr [ j ] ) + 1 ) ; } else { freq . put ( arr [ j ] , 1 ) ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 1 , 2 , 2 , 2 } ; int N = arr . length ; System . out . print ( countTuples ( arr , N ) ) ; } }

Index/key variables: j, l
Accumulator variables: ans, j, l, val
Iterator variables: j, l
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int minOperation ( int [ ] arr ) { int minOp = Integer . MIN_VALUE ; int minNeg = 0 , maxPos = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( arr [ i ] < 0 ) { if ( arr [ i ] < minNeg ) minNeg = arr [ i ] ; } else { if ( arr [ i ] > maxPos ) maxPos = arr [ i ] ; } } return Math . abs ( minNeg ) + maxPos ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 4 , 1 } ; System . out . println ( minOperation ( arr ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int GCD ( int a , int b ) { if ( b == 0 ) { return a ; } return GCD ( b , a % b ) ; } static void GcdPair ( int [ ] [ ] arr , int k ) { int lo = 0 , hi = arr . length - 1 , mid ; int [ ] ans = { - 1 , 0 } ; while ( lo <= hi ) { mid = lo + ( hi - lo ) / 2 ; if ( GCD ( arr [ mid ] [ 0 ] , arr [ mid ] [ 1 ] ) > k ) { ans = arr [ mid ] ; hi = mid - 1 ; } else lo = mid + 1 ; } if ( ans [ 0 ] == - 1 ) System . out . print ( " - 1" ) ; else System . out . print ( " ( ▁ " + ans [ 0 ] + " , ▁ " + ans [ 1 ] + " ▁ ) " ) ; return ; } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 3 , 6 } , { 15 , 30 } , { 25 , 75 } , { 30 , 120 } } ; int K = 16 ; GcdPair ( arr , K ) ; } }

Index/key variables: mid
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void isPossible ( int arr [ ] , int N ) { int mn = Integer . MAX_VALUE ; int [ ] B = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { mn = Math . min ( mn , arr [ i ] ) ; B [ i ] = arr [ i ] ; } Arrays . sort ( arr ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != B [ i ] ) { if ( B [ i ] % mn != 0 ) { System . out . print ( " No " ) ; return ; } } } System . out . print ( " Yes " ) ; return ; } public static void main ( String [ ] args ) { int N = 6 ; int arr [ ] = { 4 , 3 , 6 , 6 , 2 , 9 } ; isPossible ( arr , N ) ; } }

Index/key variables: N, i
Accumulator variables: i
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 addEdge ( ArrayList < ArrayList < Integer > > adj , int u , int v ) { adj . get ( u ) . add ( v ) ; adj . get ( v ) . add ( u ) ; } static void DFSUtil ( int u , ArrayList < ArrayList < Integer > > adj , boolean [ ] visited , int componentMin , int componentMax ) { visited [ u ] = true ; componentMax = Math . max ( componentMax , u ) ; componentMin = Math . min ( componentMin , u ) ; for ( int i = 0 ; i < adj . get ( u ) . size ( ) ; i ++ ) if ( visited [ adj . get ( u ) . get ( i ) ] == false ) DFSUtil ( adj . get ( u ) . get ( i ) , adj , visited , componentMin , componentMax ) ; } static boolean isValid ( ArrayList < pair > v ) { int MAX = - 1 ; boolean ans = false ; for ( pair i : v ) { if ( i . first <= MAX ) { ans = true ; } MAX = Math . max ( MAX , i . second ) ; } return ( ans == false ? true : false ) ; } static void DFS ( ArrayList < ArrayList < Integer > > adj , int V ) { ArrayList < pair > v = new ArrayList < > ( ) ; boolean [ ] visited = new boolean [ V + 1 ] ; for ( int u = 1 ; u <= V ; u ++ ) { if ( visited [ u ] == false ) { int componentMax = u ; int componentMin = u ; DFSUtil ( u , adj , visited , componentMin , componentMax ) ; v . add ( new pair ( componentMin , componentMax ) ) ; } } boolean check = isValid ( v ) ; if ( check ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; return ; } public static void main ( String [ ] args ) { int N = 4 , K = 3 ; ArrayList < ArrayList < Integer > > adj = new ArrayList < > ( ) ; for ( int i = 0 ; i <= N + 1 ; i ++ ) adj . add ( new ArrayList < > ( ) ) ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 2 , 3 ) ; addEdge ( adj , 3 , 4 ) ; DFS ( adj , N ) ; } }

Index/key variables: u
Accumulator variables: i, u
Iterator variables: i, u
Boolean variables: ans
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static boolean checkArrInStack ( Stack < Integer > s , int arr [ ] , int n ) { HashMap < Integer , Integer > freq = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( freq . containsKey ( arr [ i ] ) ) freq . put ( arr [ i ] , freq . get ( arr [ i ] ) + 1 ) ; else freq . put ( arr [ i ] , 1 ) ; while ( ! s . isEmpty ( ) ) { int poppedEle = s . peek ( ) ; s . pop ( ) ; if ( freq . containsKey ( poppedEle ) ) freq . put ( poppedEle , freq . get ( poppedEle ) - 1 ) ; } if ( freq . size ( ) == 0 ) return false ; return true ; } public static void main ( String [ ] args ) { Stack < Integer > s = new Stack < Integer > ( ) ; s . add ( 10 ) ; s . add ( 20 ) ; s . add ( 30 ) ; s . add ( 40 ) ; s . add ( 50 ) ; int arr [ ] = { 20 , 30 } ; int n = arr . length ; if ( checkArrInStack ( s , arr , n ) ) System . out . print ( "YESNEW_LINE"); else System . out . print ( "NONEW_LINE"); } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int longDelSub ( String str1 , String str2 ) { int N = str1 . length ( ) ; int M = str2 . length ( ) ; int prev_pos = 0 ; int pos [ ] = new int [ M ] ; for ( int i = 0 ; i < M ; i ++ ) { int index = prev_pos ; while ( index < N && str1 . charAt ( index ) != str2 . charAt ( i ) ) { index ++ ; } pos [ i ] = index ; prev_pos = index + 1 ; } int res = N - prev_pos ; prev_pos = N - 1 ; for ( int i = M - 1 ; i >= 0 ; i -- ) { int index = prev_pos ; while ( index >= 0 && str1 . charAt ( index ) != str2 . charAt ( i ) ) { index -- ; } if ( i != 0 ) { res = Math . max ( res , index - pos [ i - 1 ] - 1 ) ; } prev_pos = index - 1 ; } res = Math . max ( res , prev_pos + 1 ) ; return res ; } public static void main ( String [ ] args ) { String str1 = " GeeksforGeeks " ; String str2 = " forks " ; System . out . print ( longDelSub ( str1 , str2 ) ) ; } }

Index/key variables: M, i
Accumulator variables: i, index
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void print_substring ( String s ) { int n = s . length ( ) ; String str = " " ; Vector < Integer > ans = new Vector < Integer > ( ) ; if ( n == 0 ) { System . out . print ( " - 1" ) ; return ; } int [ ] last_pos = new int [ 26 ] ; Arrays . fill ( last_pos , - 1 ) ; for ( int i = n - 1 ; i >= 0 ; -- i ) { if ( last_pos [ s . charAt ( i ) - ' a ' ] == - 1 ) { last_pos [ s . charAt ( i ) - ' a ' ] = i ; } } int minp = - 1 ; for ( int i = 0 ; i < n ; ++ i ) { int lp = last_pos [ s . charAt ( i ) - ' a ' ] ; minp = Math . max ( minp , lp ) ; if ( i == minp ) { str += s . charAt ( i ) ; System . out . print ( str + ' ▁ ' ) ; minp = - 1 ; str = " " ; } else { str += s . charAt ( i ) ; } } } public static void main ( String [ ] args ) { String S = " ababcbacadefegdehijhklij " ; print_substring ( S ) ; } }

Accumulator variables: str
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void partitionString ( String s ) { int n = s . length ( ) ; Vector < Integer > ans = new Vector < Integer > ( ) ; if ( n == 0 ) { System . out . print ( " - 1" ) ; return ; } int [ ] last_pos = new int [ 26 ] ; Arrays . fill ( last_pos , - 1 ) ; for ( int i = n - 1 ; i >= 0 ; -- i ) { if ( last_pos [ s . charAt ( i ) - ' a ' ] == - 1 ) { last_pos [ s . charAt ( i ) - ' a ' ] = i ; } } int minp = - 1 , plen = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int lp = last_pos [ s . charAt ( i ) - ' a ' ] ; minp = Math . max ( minp , lp ) ; ++ plen ; if ( i == minp ) { ans . add ( plen ) ; minp = - 1 ; plen = 0 ; } } for ( int i = 0 ; i < ( int ) ans . size ( ) ; i ++ ) { System . out . print ( ans . get ( i ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { String str = " acbbcc " ; partitionString ( str ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void solve ( String S ) { int count_0 = 0 , count_1 = 0 ; int prev = - 1 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == '0' ) count_0 ++ ; else if ( S . charAt ( i ) == '1' ) count_1 ++ ; } for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == ' * ' ) continue ; else if ( S . charAt ( i ) == '0' && prev == - 1 ) { count_0 = count_0 + i ; prev = i ; } else if ( S . charAt ( i ) == '1' && prev == - 1 ) { prev = i ; } else if ( S . charAt ( prev ) == '1' && S . charAt ( i ) == '0' ) { count_0 = count_0 + ( i - prev - 1 ) / 2 ; count_1 = count_1 + ( i - prev - 1 ) / 2 ; prev = i ; } else if ( S . charAt ( prev ) == '1' && S . charAt ( i ) == '1' ) { count_1 = count_1 + ( i - prev - 1 ) ; prev = i ; } else if ( S . charAt ( prev ) == '0' && S . charAt ( i ) == '1' ) prev = i ; else if ( S . charAt ( prev ) == '0' && S . charAt ( i ) == '0' ) { count_0 = count_0 + ( i - prev - 1 ) ; prev = i ; } } if ( count_0 > count_1 ) System . out . print ( "0" ) ; else if ( count_1 > count_0 ) System . out . print ( "1" ) ; else { System . out . print ( " - 1" ) ; } } public static void main ( String [ ] args ) { String str = " * *0 * * 1 * * *0" ; solve ( str ) ; } }

Accumulator variables: count_0, count_1, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minFirstTerm ( int X , int diff , int N ) { int first_term = Integer . MAX_VALUE ; int low = 0 , high = N ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( X - mid * diff > 0 ) { first_term = X - mid * diff ; low = mid + 1 ; } else high = mid - 1 ; } return first_term ; } static void printAP ( int N , int X , int Y ) { if ( X > Y ) { X = X + Y ; Y = X - Y ; X = X - Y ; } int maxDiff = Y - X ; int first_term = Integer . MAX_VALUE , diff = 0 ; for ( int i = 1 ; i * i <= maxDiff ; i ++ ) { if ( maxDiff % i == 0 ) { int diff1 = i ; int diff2 = maxDiff / diff1 ; int terms1 = diff2 + 1 ; int terms2 = diff1 + 1 ; int first_term1 = minFirstTerm ( X , diff1 , N - terms1 ) ; int first_term2 = minFirstTerm ( X , diff2 , N - terms2 ) ; if ( first_term1 < first_term ) { first_term = first_term1 ; diff = diff1 ; } if ( first_term2 < first_term ) { first_term = first_term2 ; diff = diff2 ; } } } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( first_term + " ▁ " ) ; first_term += diff ; } } public static void main ( String [ ] args ) { int N = 5 , X = 10 , Y = 15 ; printAP ( N , X , Y ) ; } }

Accumulator variables: first_term, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isCubeSum ( int n ) { for ( int i = 1 ; i * i * i <= n ; i ++ ) { if ( i * i * i + ( i + 1 ) * ( i + 1 ) * ( i + 1 ) == n ) return true ; } return false ; } public static void main ( String [ ] args ) { int n = 35 ; if ( isCubeSum ( n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static boolean isSumCube ( int N ) { int a = ( int ) Math . cbrt ( N ) ; int b = a - 1 ; return ( ( a * a * a + b * b * b ) == N ) ; } public static void main ( String [ ] args ) { int i = 35 ; if ( isSumCube ( i ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxweight ( int s , int e , Map < Integer , Integer > pre ) { if ( s == e ) return 0 ; int ans = 0 ; for ( int i = s ; i < e ; i ++ ) { int left = pre . get ( i ) - pre . get ( s - 1 ) ; int right = pre . get ( e ) - pre . get ( i ) ; if ( left < right ) ans = Math . max ( ans , left + maxweight ( s , i , pre ) ) ; if ( left == right ) { ans = Math . max ( ans , Math . max ( left + maxweight ( s , i , pre ) , right + maxweight ( i + 1 , e , pre ) ) ) ; } if ( left > right ) ans = Math . max ( ans , right + maxweight ( i + 1 , e , pre ) ) ; } return ans ; } static void maxSum ( List < Integer > arr ) { Map < Integer , Integer > pre = new HashMap < > ( ) ; pre . put ( - 1 , 0 ) ; pre . put ( 0 , arr . get ( 0 ) ) ; for ( int i = 1 ; i < arr . size ( ) ; i ++ ) { pre . put ( i , pre . getOrDefault ( i - 1 , 0 ) + arr . get ( i ) ) ; } System . out . println ( maxweight ( 0 , arr . size ( ) - 1 , pre ) ) ; } public static void main ( String [ ] args ) { List < Integer > arr = Arrays . asList ( 6 , 2 , 3 , 4 , 5 , 5 ) ; maxSum ( arr ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String largestTimeFromDigits ( int [ ] A ) { HashMap < Integer , Integer > mp1 = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Integer > mp2 = new HashMap < Integer , Integer > ( ) ; for ( int x : A ) { if ( mp1 . containsKey ( x ) ) mp1 . put ( x , mp1 . get ( x ) + 1 ) ; else mp1 . put ( x , 1 ) ; } mp2 = ( HashMap < Integer , Integer > ) mp1 . clone ( ) ; int hr = 23 , m = 59 , s = 59 ; while ( hr >= 0 ) { int h0 = hr / 10 , h1 = hr % 10 ; int m0 = m / 10 , m1 = m % 10 ; int s0 = s / 10 , s1 = s % 10 ; int p = 0 ; int [ ] arr = { h0 , h1 , m0 , m1 , s0 , s1 } ; for ( int it : arr ) { if ( mp1 . containsKey ( it ) && mp1 . get ( it ) > 0 ) { mp1 . put ( it , mp1 . get ( it ) - 1 ) ; } else { p = 1 ; } } if ( p == 0 ) { String st = " " ; st = String . valueOf ( h0 ) + String . valueOf ( h1 ) ; st += ' : ' + String . valueOf ( m0 ) + String . valueOf ( m1 ) ; st += ' : ' + String . valueOf ( s0 ) + String . valueOf ( s1 ) ; return st ; } mp1 = ( HashMap < Integer , Integer > ) mp2 . clone ( ) ; if ( s == 0 ) { s = 59 ; m -- ; } else if ( m < 0 ) { m = 59 ; hr -- ; } if ( s > 0 ) { s -- ; } } return " - 1" ; } public static void main ( String [ ] args ) { int [ ] v = { 0 , 2 , 1 , 9 , 3 , 2 } ; System . out . print ( largestTimeFromDigits ( v ) ) ; } }

Accumulator variables: hr, m, s, st
Iterator variables: it, x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String palindromePrefix ( String S ) { int n = S . length ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { String curr = S . substring ( 0 , i + 1 ) ; int l = 0 , r = curr . length ( ) - 1 ; boolean is_palindrome = true ; while ( l < r ) { if ( curr . charAt ( l ) != curr . charAt ( r ) ) { is_palindrome = false ; break ; } l ++ ; r -- ; } if ( is_palindrome ) return curr ; } return " " ; } static String maxPalindrome ( String S ) { int n = S . length ( ) ; if ( n <= 1 ) { return S ; } String pre = " " , suff = " " ; int i = 0 , j = n - 1 ; while ( S . charAt ( i ) == S . charAt ( j ) && i < j ) { i ++ ; j -- ; } i -- ; j ++ ; pre = S . substring ( 0 , i + 1 ) ; suff = S . substring ( j ) ; if ( j - i == 1 ) { return pre + suff ; } if ( j - i == 2 ) { String mid_char = S . substring ( i + 1 , i + 2 ) ; return pre + mid_char + suff ; } String rem_str = S . substring ( i + 1 , j ) ; String pre_of_rem_str = palindromePrefix ( rem_str ) ; rem_str = reverse ( rem_str ) ; String suff_of_rem_str = palindromePrefix ( rem_str ) ; if ( pre_of_rem_str . length ( ) >= suff_of_rem_str . length ( ) ) { return pre + pre_of_rem_str + suff ; } else { return pre + suff_of_rem_str + suff ; } } static String reverse ( String input ) { char [ ] a = input . toCharArray ( ) ; int l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . valueOf ( a ) ; } public static void main ( String [ ] args ) { String S = " geeksforskeeg " ; System . out . print ( maxPalindrome ( S ) ) ; } }

Index/key variables: l, r
Accumulator variables: i, j, l, r
Iterator variables: i, l
Boolean variables: is_palindrome
Class/struct names: GFG
Java program:
class GFG { static void countNumEnds ( int A , int L , int R ) { int temp , count = 0 , digits ; int cycle ; digits = ( int ) ( Math . log10 ( A ) + 1 ) ; temp = ( int ) Math . pow ( 10 , digits ) ; cycle = temp ; while ( temp <= R ) { if ( temp >= L ) count ++ ; temp += cycle ; } System . out . print ( count ) ; } public static void main ( String [ ] args ) { int A = 2 , L = 2 , R = 20 ; countNumEnds ( A , L , R ) ; } }

Accumulator variables: count, temp
Class/struct names: GFG
Java program:
class GFG { public static int minOperations ( String s ) { int len = s . length ( ) ; int result = 0 ; for ( int i = 0 ; i < len / 2 ; i ++ ) { int D1 = Math . max ( s . charAt ( i ) , s . charAt ( len - 1 - i ) ) - Math . min ( s . charAt ( i ) , s . charAt ( len - 1 - i ) ) ; int D2 = 26 - D1 ; result += Math . min ( D1 , D2 ) ; } return result ; } public static void main ( String [ ] args ) { String s = " abccdb " ; System . out . println ( minOperations ( s ) ) ; } }

Accumulator variables: i, result
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean findFactor ( int value , HashSet < Integer > factors ) { factors . add ( value ) ; for ( int i = 2 ; i * i <= value ; i ++ ) { if ( value % i == 0 ) { if ( value / i == i ) { if ( factors . contains ( i ) ) { return true ; } else { factors . add ( i ) ; } } else { if ( factors . contains ( i ) || factors . contains ( value / i ) ) { return true ; } else { factors . add ( i ) ; factors . add ( value / i ) ; } } } } return false ; } static boolean allCoprime ( int A [ ] , int n ) { boolean all_coprime = true ; HashSet < Integer > factors = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( A [ i ] == 1 ) continue ; if ( findFactor ( A [ i ] , factors ) ) { all_coprime = false ; break ; } } return all_coprime ; } public static void main ( String [ ] args ) { int A [ ] = { 3 , 5 , 11 , 7 , 19 } ; int arr_size = A . length ; if ( allCoprime ( A , arr_size ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }

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