dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { public static int findMinLength ( String s ) { int n = s . length ( ) ; HashMap < Character , Integer > counts = new HashMap < > ( ) ; Vector < Integer > indices = new Vector < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' a ' || s . charAt ( i ) == ' e ' || s . charAt ( i ) == ' o ' || s . charAt ( i ) == ' i ' || s . charAt ( i ) == ' u ' ) { if ( counts . containsKey ( s . charAt ( i ) ) ) { counts . replace ( s . charAt ( i ) , counts . get ( s . charAt ( i ) ) + 1 ) ; } else { counts . put ( s . charAt ( i ) , 1 ) ; } indices . add ( i ) ; } } if ( counts . size ( ) < 5 ) return - 1 ; int flag1 = 0 , flag2 = 0 ; int i = 0 ; int j = indices . size ( ) - 1 ; while ( ( j - i ) >= 4 ) { if ( flag1 == 0 && counts . get ( s . charAt ( indices . get ( i ) ) ) > 1 ) { counts . replace ( s . charAt ( indices . get ( i ) ) , counts . get ( s . charAt ( indices . get ( i ) ) ) - 1 ) ; i ++ ; } else flag1 = 1 ; if ( flag2 == 0 && counts . get ( s . charAt ( indices . get ( j ) ) ) > 1 ) { counts . replace ( s . charAt ( indices . get ( j ) ) , counts . get ( s . charAt ( indices . get ( j ) ) ) - 1 ) ; j -- ; } else flag2 = 1 ; if ( flag1 == 1 && flag2 == 1 ) break ; } return ( indices . get ( j ) - indices . get ( i ) + 1 ) ; } public static void main ( String [ ] args ) { String s = " aaeebbeaccaaoiuooooooooiuu " ; System . out . print ( findMinLength ( s ) ) ; } }

Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static boolean isConsonants ( char x ) { x = Character . toLowerCase ( x ) ; return ! ( x == ' a ' x == ' e ' x == ' i ' x == ' o ' x == ' u ' ) ; } static String longestConsonantsSubsequence ( String str ) { String answer = " " ; int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( isConsonants ( str . charAt ( i ) ) ) { answer += str . charAt ( i ) ; } } return answer ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; System . out . print ( longestConsonantsSubsequence ( str ) + "NEW_LINE"); } }

Accumulator variables: answer, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int lengthOfSubsequence ( String str , int K ) { Map < Character , Integer > mp = new HashMap < > ( ) ; for ( char ch : str . toCharArray ( ) ) { mp . put ( ch , mp . getOrDefault ( ch , 0 ) + 1 ) ; } int minimum = mp . get ( ' A ' ) ; for ( int i = 1 ; i < K ; i ++ ) { minimum = Math . min ( minimum , mp . get ( ( char ) ( i + ' A ' ) ) ) ; } return minimum * K ; } public static void main ( String [ ] args ) { String str = " ACAABCCAB " ; int K = 3 ; System . out . println ( lengthOfSubsequence ( str , K ) ) ; } }

Accumulator variables: i
Iterator variables: ch, i
Class/struct names: GFG
Java program:
class GFG { static final int V = 4 ; static final int INF = 99999 ; static boolean negCyclefloydWarshall ( int graph [ ] [ ] ) { int dist [ ] [ ] = new int [ V ] [ V ] , i , j , k ; for ( i = 0 ; i < V ; i ++ ) for ( j = 0 ; j < V ; j ++ ) dist [ i ] [ j ] = graph [ i ] [ j ] ; for ( k = 0 ; k < V ; k ++ ) { for ( i = 0 ; i < V ; i ++ ) { for ( j = 0 ; j < V ; j ++ ) { if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) dist [ i ] [ j ] = dist [ i ] [ k ] + dist [ k ] [ j ] ; } } } for ( i = 0 ; i < V ; i ++ ) if ( dist [ i ] [ i ] < 0 ) return true ; return false ; } public static void main ( String [ ] args ) { int graph [ ] [ ] = { { 0 , 1 , INF , INF } , { INF , 0 , - 1 , INF } , { INF , INF , 0 , - 1 } , { - 1 , INF , INF , 0 } } ; if ( negCyclefloydWarshall ( graph ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Index/key variables: V, i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
class GFG { static String convertToString ( int sum ) { String str = " " ; while ( sum > 0 ) { str = str + ( char ) ( ( sum % 10 ) + '0' ) ; sum = sum / 10 ; } return str ; } static String GetIndividulaDigitSum ( String str , int len ) { int sum = 0 ; for ( int i = 0 ; i < len ; i ++ ) { sum = sum + str . charAt ( i ) - '0' ; } return convertToString ( sum ) ; } static int GetDigitalRoot ( String str ) { if ( str . length ( ) == 1 ) { return str . charAt ( 0 ) - '0' ; } str = GetIndividulaDigitSum ( str , str . length ( ) ) ; return GetDigitalRoot ( str ) ; } public static void main ( String [ ] args ) { String str = "675987890789756545689070986776987" ; System . out . print ( GetDigitalRoot ( str ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void count ( String str1 , String str2 ) { int c = 0 , j = 0 ; for ( int i = 0 ; i < str1 . length ( ) ; i ++ ) { if ( str2 . indexOf ( str1 . charAt ( i ) ) >= 0 ) { c += 1 ; } } System . out . println ( " No . ▁ of ▁ matching ▁ characters ▁ are : ▁ " + c ) ; } public static void main ( String [ ] args ) { String str1 = " aabcddekll12 @ " ; String str2 = " bb2211@55k " ; count ( str1 , str2 ) ; } }

Accumulator variables: c, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int countOfLetters ( String str ) { int letter = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) || ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) ) letter ++ ; } return letter ; } static int countOfNumbers ( String str ) { int number = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) >= '0' && str . charAt ( i ) <= '9' ) number ++ ; } return number ; } static void check ( String str ) { if ( countOfLetters ( str ) == countOfNumbers ( str ) ) System . out . print ( "YesNEW_LINE"); else System . out . print ( "NoNEW_LINE"); } public static void main ( String [ ] args ) { String str = " GeeKs01324" ; check ( str ) ; } }

Accumulator variables: i, letter, number
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findMinCost ( char [ ] s , int i , int j ) { Vector < Integer > [ ] gr = new Vector [ 26 ] ; for ( int iN = 0 ; iN < 26 ; iN ++ ) gr [ iN ] = new Vector < Integer > ( ) ; boolean [ ] [ ] edge = new boolean [ 26 ] [ 26 ] ; for ( int k = 0 ; k < 26 ; k ++ ) for ( int l = 0 ; l < 26 ; l ++ ) edge [ k ] [ l ] = false ; for ( int k = 0 ; k < s . length ; k ++ ) { if ( k - 1 >= 0 && ! edge [ s [ k ] - 97 ] [ s [ k - 1 ] - 97 ] ) { gr [ s [ k ] - 97 ] . add ( s [ k - 1 ] - 97 ) ; edge [ s [ k ] - 97 ] [ s [ k - 1 ] - 97 ] = true ; } if ( k + 1 <= s . length - 1 && ! edge [ s [ k ] - 97 ] [ s [ k + 1 ] - 97 ] ) { gr [ s [ k ] - 97 ] . add ( s [ k + 1 ] - 97 ) ; edge [ s [ k ] - 97 ] [ s [ k + 1 ] - 97 ] = true ; } } Queue < Integer > q = new LinkedList < Integer > ( ) ; q . add ( s [ i ] - 97 ) ; boolean [ ] v = new boolean [ 26 ] ; int d = 0 ; while ( q . size ( ) > 0 ) { int cnt = q . size ( ) ; while ( cnt -- > 0 ) { int curr = q . peek ( ) ; q . remove ( ) ; if ( v [ curr ] ) continue ; v [ curr ] = true ; if ( curr == s [ j ] - 97 ) return d ; for ( Integer it : gr [ curr ] ) q . add ( it ) ; } d ++ ; } return - 1 ; } public static void main ( String [ ] args ) { String s = " abcde " ; int i = 0 ; int j = 4 ; System . out . print ( findMinCost ( s . toCharArray ( ) , i , j ) ) ; } }

Index/key variables: curr, i, iN, j, k, l
Accumulator variables: cnt, d, iN, k, l
Iterator variables: iN, it, k, l
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static boolean twoColorUtil ( Vector < Integer > [ ] G , int src , int N , int [ ] colorArr ) { colorArr [ src ] = 1 ; Queue < Integer > q = new LinkedList < > ( ) ; q . add ( src ) ; while ( ! q . isEmpty ( ) ) { int u = q . peek ( ) ; q . poll ( ) ; for ( int v = 0 ; v < G [ u ] . size ( ) ; ++ v ) { if ( colorArr [ G [ u ] . elementAt ( v ) ] == - 1 ) { colorArr [ G [ u ] . elementAt ( v ) ] = 1 - colorArr [ u ] ; q . add ( G [ u ] . elementAt ( v ) ) ; } else if ( colorArr [ G [ u ] . elementAt ( v ) ] == colorArr [ u ] ) return false ; } } return true ; } static boolean twoColor ( Vector < Integer > [ ] G , int N ) { int [ ] colorArr = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; ++ i ) colorArr [ i ] = - 1 ; for ( int i = 1 ; i <= N ; i ++ ) if ( colorArr [ i ] == - 1 ) if ( twoColorUtil ( G , i , N , colorArr ) == false ) return false ; return true ; } static boolean isOddSum ( int [ ] [ ] info , int n , int m ) { Vector < Integer > [ ] G = new Vector [ 2 * n ] ; for ( int i = 0 ; i < 2 * n ; i ++ ) G [ i ] = new Vector < > ( ) ; int pseudo = n + 1 ; int pseudo_count = 0 ; for ( int i = 0 ; i < m ; i ++ ) { if ( info [ i ] [ 2 ] % 2 == 1 ) { int u = info [ i ] [ 0 ] ; int v = info [ i ] [ 1 ] ; G [ u ] . add ( v ) ; G [ v ] . add ( u ) ; } else { int u = info [ i ] [ 0 ] ; int v = info [ i ] [ 1 ] ; G [ u ] . add ( pseudo ) ; G [ pseudo ] . add ( u ) ; G [ v ] . add ( pseudo ) ; G [ pseudo ] . add ( v ) ; pseudo_count ++ ; pseudo ++ ; } } return twoColor ( G , n + pseudo_count ) ; } public static void main ( String [ ] args ) { int n = 4 , m = 3 ; int [ ] [ ] info = { { 1 , 2 , 12 } , { 2 , 3 , 1 } , { 4 , 3 , 1 } , { 4 , 1 , 20 } } ; if ( isOddSum ( info , n , m ) == true ) System . out . println ( " No " ) ; else System . out . println ( " Yes " ) ; } }

Index/key variables: i, pseudo, src, u, v
Accumulator variables: i, pseudo, pseudo_count
Iterator variables: i, v
Class/struct names: GFG
Java program:
class GFG { static int MAX = 26 ; static void performQueries ( String str , int q , int type [ ] , char ch [ ] , int freq [ ] ) { int n = str . length ( ) ; int [ ] [ ] L = new int [ MAX ] [ n ] ; int [ ] [ ] F = new int [ MAX ] [ n ] ; int [ ] cnt = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { int k = str . charAt ( i ) - ' a ' ; cnt [ k ] ++ ; for ( int j = 0 ; j < MAX ; j ++ ) { if ( k == j ) { L [ j ] [ cnt [ j ] ] = i ; F [ j ] [ cnt [ j ] ] = i ; } else L [ j ] [ cnt [ j ] ] = L [ j ] [ cnt [ j ] ] + 1 ; } } for ( int i = 0 ; i < q ; i ++ ) { if ( type [ i ] == 1 ) { System . out . print ( L [ ch [ i ] - ' a ' ] [ freq [ i ] ] ) ; } else { System . out . print ( F [ ch [ i ] - ' a ' ] [ freq [ i ] ] ) ; } System . out . print ( "NEW_LINE"); } } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int type [ ] = { 1 , 2 } ; char ch [ ] = { ' e ' , ' k ' } ; int freq [ ] = { 2 , 2 } ; int q = type . length ; performQueries ( str , q , type , ch , freq ) ; } }

Index/key variables: MAX, i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int anagram_pairs ( String [ ] s , int n ) { Map < String , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { char [ ] chArr = s [ i ] . toCharArray ( ) ; Arrays . sort ( chArr ) ; s [ i ] = new String ( chArr ) ; if ( mp . containsKey ( s [ i ] ) ) { mp . put ( s [ i ] , mp . get ( s [ i ] ) + 1 ) ; } else { mp . put ( s [ i ] , 1 ) ; } } int ans = 0 ; for ( Map . Entry < String , Integer > i : mp . entrySet ( ) ) { int k = i . getValue ( ) ; ans += ( k * ( k - 1 ) ) / 2 ; } return ans ; } public static void main ( String [ ] args ) { String [ ] s = { " aaab " , " aaba " , " baaa " , " cde " , " dec " } ; int n = s . length ; System . out . println ( anagram_pairs ( s , n ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static char Insert ( char arr [ ] , int n , int k ) { int ind = 0 ; int sz = 0 ; String s = " " ; char ch = arr [ 0 ] ; s += ch ; sz = 1 ; ind = 0 ; for ( int i = 1 ; i < n ; i ++ ) { ch = arr [ i ] ; String s1 = s . substring ( 0 , ind + 1 ) ; int temp = k % sz ; int ro = temp - Math . min ( temp , sz - ind - 1 ) ; if ( ro == 0 ) { String s2 = s . substring ( ind + 1 , ind + 1 + temp ) ; String s3 = s . substring ( ind + temp + 1 , sz ) ; s = s1 + s2 + ch + s3 ; ind = s1 . length ( ) + s2 . length ( ) ; sz = s . length ( ) ; } else { String s2 = s . substring ( 0 , ro ) ; String s3 = s . substring ( ro , sz ) ; s = s2 + ch + s3 ; ind = s2 . length ( ) ; sz = s . length ( ) ; } } if ( ind == 0 ) { return s . charAt ( sz - 1 ) ; } else { return s . charAt ( ind - 1 ) ; } } public static void main ( String [ ] args ) { char arr [ ] = { '1' , '2' , '3' , '4' , '5' } ; int k = 2 ; int n = arr . length ; System . out . println ( Insert ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, s
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Vector ; class GFG { static boolean isCycleRec ( int v , Vector < Integer > [ ] adj , Vector < Boolean > visited , Vector < Boolean > recur ) { visited . set ( v , true ) ; recur . set ( v , true ) ; for ( int i = 0 ; i < adj [ v ] . size ( ) ; i ++ ) { if ( visited . elementAt ( adj [ v ] . elementAt ( i ) ) == false ) { if ( isCycleRec ( adj [ v ] . elementAt ( i ) , adj , visited , recur ) ) return true ; } else if ( visited . elementAt ( adj [ v ] . elementAt ( i ) ) == true && recur . elementAt ( adj [ v ] . elementAt ( i ) ) == true ) return true ; } recur . set ( v , false ) ; return false ; } @ SuppressWarnings ( " unchecked " ) static boolean isCycle ( int [ ] arr , int n ) { Vector < Integer > [ ] adj = new Vector [ n ] ; for ( int i = 0 ; i < n ; i ++ ) if ( i != ( i + arr [ i ] + n ) % n && adj [ i ] != null ) adj [ i ] . add ( ( i + arr [ i ] + n ) % n ) ; Vector < Boolean > visited = new Vector < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) visited . add ( true ) ; Vector < Boolean > recur = new Vector < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) recur . add ( true ) ; for ( int i = 0 ; i < n ; i ++ ) if ( visited . elementAt ( i ) == false ) if ( isCycleRec ( i , adj , visited , recur ) ) return true ; return true ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , - 1 , 1 , 2 , 2 } ; int n = arr . length ; if ( isCycle ( arr , n ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, n, v
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static final int MAX = 256 ; static int freq [ ] [ ] ; static void preCalculate ( String str , int n ) { freq [ ( int ) str . charAt ( 0 ) ] [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { char ch = str . charAt ( i ) ; for ( int j = 0 ; j < MAX ; j ++ ) { char charToUpdate = ( char ) j ; if ( charToUpdate == ch ) freq [ j ] [ i ] = freq [ j ] [ i - 1 ] + 1 ; else freq [ j ] [ i ] = freq [ j ] [ i - 1 ] ; } } } static int getFrequency ( char ch , int l , int r ) { if ( l == 0 ) return freq [ ( int ) ch ] [ r ] ; else return ( freq [ ( int ) ch ] [ r ] - freq [ ( int ) ch ] [ l - 1 ] ) ; } static String lastNonRepeating ( String str , int n , int l , int r ) { for ( int i = r ; i >= l ; i -- ) { char ch = str . charAt ( i ) ; if ( getFrequency ( ch , l , r ) == 1 ) return ( " " + ch ) ; } return " - 1" ; } public static void main ( String [ ] args ) { String str = " GeeksForGeeks " ; int n = str . length ( ) ; int queries [ ] [ ] = { { 2 , 9 } , { 2 , 3 } , { 0 , 12 } } ; int q = queries . length ; freq = new int [ MAX ] [ n ] ; preCalculate ( str , n ) ; for ( int i = 0 ; i < q ; i ++ ) { System . out . println ( lastNonRepeating ( str , n , queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ) ; } } }

Index/key variables: MAX, i, j, n, r
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void pre_process ( String substrings [ ] , String s ) { int n = s . length ( ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { String dup = " " ; for ( int j = i ; j < n ; j ++ ) { dup += s . charAt ( j ) ; substrings [ count ++ ] = dup ; } } int size = substrings . length ; for ( int i = 0 ; i < size - 1 ; i ++ ) { for ( int j = i + 1 ; j < substrings . length ; j ++ ) { if ( substrings [ i ] . compareTo ( substrings [ j ] ) > 0 ) { String temp = substrings [ i ] ; substrings [ i ] = substrings [ j ] ; substrings [ j ] = temp ; } } } } public static void main ( String args [ ] ) { String s = " geek " ; String substrings [ ] = new String [ 10 ] ; pre_process ( substrings , s ) ; int queries [ ] = { 1 , 5 , 10 } ; int q = queries . length ; for ( int i = 0 ; i < q ; i ++ ) System . out . println ( substrings [ queries [ i ] - 1 ] ) ; } }

Index/key variables: i, j
Accumulator variables: count, dup, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class Priority { String s ; int count ; } class PQ implements Comparator < Priority > { public int compare ( Priority a , Priority b ) { if ( a . count > b . count ) return 1 ; else if ( a . count < b . count ) return - 1 ; return 0 ; } } class GFG { static void FindString ( String str [ ] , int num [ ] , int n ) { Comparator < Priority > comparator = new PQ ( ) ; PriorityQueue < Priority > p = new PriorityQueue < Priority > ( comparator ) ; for ( int i = 0 ; i < n ; i ++ ) { Priority x = new Priority ( ) ; x . s = str [ i ] ; x . count = num [ i ] ; p . add ( x ) ; } while ( p . size ( ) > 1 ) { Priority x = p . poll ( ) ; p . remove ( x ) ; Priority y = p . poll ( ) ; p . remove ( y ) ; int temp = x . count + y . count ; String sb = x . s + y . s ; Priority z = new Priority ( ) ; z . count = temp ; z . s = sb ; p . add ( z ) ; } Priority z = p . poll ( ) ; System . out . println ( z . s ) ; } public static void main ( String [ ] args ) { String str [ ] = { " Geeks " , " For " , " Geeks " } ; int num [ ] = { 2 , 3 , 7 } ; int n = num . length ; FindString ( str , num , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, PQ, Priority
Java program:
import java . util . Arrays ; class GFG { static int minCost ( String str , int K ) { int n = str . length ( ) ; int res = 999999999 , count = 0 , a , b ; int cnt [ ] = new int [ 27 ] ; Arrays . fill ( cnt , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) cnt [ str . charAt ( i ) - ' a ' + 1 ] ++ ; for ( int i = 1 ; i < ( 26 - K + 1 ) ; i ++ ) { a = i ; b = i + K ; count = 0 ; for ( int j = 1 ; j <= 26 ; j ++ ) { if ( cnt [ j ] > 0 ) { if ( j >= a && j >= b ) count = count + ( Math . min ( j - b , 25 - j + a + 1 ) ) * cnt [ j ] ; else if ( j <= a && j <= b ) count = count + ( Math . min ( a - j , 25 + j - b + 1 ) ) * cnt [ j ] ; } } res = Math . min ( res , count ) ; } for ( int i = 26 - K + 1 ; i <= 26 ; i ++ ) { a = i ; b = ( i + K ) % 26 ; count = 0 ; for ( int j = 1 ; j <= 26 ; j ++ ) { if ( cnt [ j ] > 0 ) { if ( j >= b && j <= a ) count = count + ( Math . min ( j - b , a - j ) ) * cnt [ j ] ; } } res = Math . min ( res , count ) ; } return res ; } public static void main ( String [ ] args ) { String str = " abcdefghi " ; int K = 2 ; System . out . println ( minCost ( str , K ) ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void printBinStr ( int [ ] str , int len ) { for ( int i = 0 ; i < len ; i ++ ) { System . out . print ( str [ i ] ) ; } System . out . println ( ) ; } static void generateBinStr ( int [ ] str , int len , int currlen , int occur , int nextbit ) { if ( currlen == len ) { if ( occur == 2 && nextbit == 0 ) { printBinStr ( str , len ) ; } return ; } if ( currlen == 0 ) { str [ 0 ] = nextbit ; generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; if ( occur < 2 ) { str [ currlen ] = nextbit ; if ( str [ currlen - 1 ] == 0 && nextbit == 1 ) { occur += 1 ; } generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; if ( str [ currlen - 1 ] == 0 && nextbit == 1 ) { return ; } else { str [ currlen ] = nextbit ; generateBinStr ( str , len , currlen + 1 , occur , 0 ) ; generateBinStr ( str , len , currlen + 1 , occur , 1 ) ; } } public static void main ( String [ ] args ) { int n = 5 ; if ( n < 4 ) { System . out . print ( - 1 ) ; } else { int [ ] str = new int [ n ] ; generateBinStr ( str , n , 0 , 0 , 0 ) ; generateBinStr ( str , n , 0 , 0 , 1 ) ; } } }

Index/key variables: currlen, i, n
Accumulator variables: i, occur
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void printLastChar ( String str ) { str = str + " ▁ " ; for ( int i = 1 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == ' ▁ ' ) System . out . print ( str . charAt ( i - 1 ) + " ▁ " ) ; } } public static void main ( String s [ ] ) { String str = " Geeks ▁ for ▁ Geeks " ; printLastChar ( str ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int maxBalancedStr ( String s ) { int open1 = 0 , close1 = 0 ; int open2 = 0 , close2 = 0 ; int open3 = 0 , close3 = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { switch ( s . charAt ( i ) ) { case ' ( ' : open1 ++ ; break ; case ' ) ' : close1 ++ ; break ; case ' { ' : open2 ++ ; break ; case ' } ' : close2 ++ ; break ; case ' [ ' : open3 ++ ; break ; case ' ] ' : close3 ++ ; break ; } } int maxLen = 2 * Math . min ( open1 , close1 ) + 2 * Math . min ( open2 , close2 ) + 2 * Math . min ( open3 , close3 ) ; return maxLen ; } public static void main ( String [ ] args ) { String s = " ) ) [ ] ] ( ( " ; System . out . println ( maxBalancedStr ( s ) ) ; } }

Accumulator variables: close1, close2, close3, i, open1, open2, open3
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static String strBitwiseOR ( String [ ] arr , int n ) { String res = " " ; int max_size = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { max_size = Math . max ( max_size , ( int ) arr [ i ] . length ( ) ) ; arr [ i ] = reverse ( arr [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { String s = " " ; for ( int j = 0 ; j < max_size - arr [ i ] . length ( ) ; j ++ ) s += '0' ; arr [ i ] = arr [ i ] + s ; } for ( int i = 0 ; i < max_size ; i ++ ) { int curr_bit = 0 ; for ( int j = 0 ; j < n ; j ++ ) curr_bit = curr_bit | ( arr [ j ] . charAt ( i ) - '0' ) ; res += ( char ) ( curr_bit + '0' ) ; } res = reverse ( res ) ; return res ; } static String reverse ( String input ) { char [ ] temparray = input . toCharArray ( ) ; int left , right = 0 ; right = temparray . length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { public static void main ( String [ ] args ) { String arr [ ] = { "10" , "11" , "1000001" } ; int n = arr . length ; System . out . println ( strBitwiseOR ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, left, res, right, s
Iterator variables: i, j, left
Class/struct names: GFG
Java program:
class GFG { static int findCost ( String s1 , String s2 , int a , int b , int c , int d , int n ) { int cost = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s1 . charAt ( i ) == s2 . charAt ( i ) ) continue ; else { if ( ( s1 . charAt ( i ) == '1' && s2 . charAt ( i ) == '2' ) || ( s2 . charAt ( i ) == '1' && s1 . charAt ( i ) == '2' ) ) cost += Math . min ( d , Math . min ( a , b + c ) ) ; else if ( ( s1 . charAt ( i ) == '2' && s2 . charAt ( i ) == '3' ) || ( s2 . charAt ( i ) == '2' && s1 . charAt ( i ) == '3' ) ) cost += Math . min ( d , Math . min ( b , a + c ) ) ; else if ( ( s1 . charAt ( i ) == '1' && s2 . charAt ( i ) == '3' ) || ( s2 . charAt ( i ) == '1' && s1 . charAt ( i ) == '3' ) ) cost += Math . min ( d , Math . min ( c , a + b ) ) ; } } return cost ; } public static void main ( String [ ] args ) { String s1 = "121" ; String s2 = "223" ; int a = 2 , b = 3 , c = 4 , d = 10 ; int n = s1 . length ( ) ; System . out . println ( findCost ( s1 , s2 , a , b , c , d , n ) ) ; } }

Accumulator variables: cost, i
Iterator variables: i
Class/struct names: GFG