dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { static int matchClosing ( char X [ ] , int start , int end , char open , char close ) { int c = 1 ; int i = start + 1 ; while ( i <= end ) { if ( X [ i ] == open ) { c ++ ; } else if ( X [ i ] == close ) { c -- ; } if ( c == 0 ) { return i ; } i ++ ; } return i ; } static int matchingOpening ( char X [ ] , int start , int end , char open , char close ) { int c = - 1 ; int i = end - 1 ; while ( i >= start ) { if ( X [ i ] == open ) { c ++ ; } else if ( X [ i ] == close ) { c -- ; } if ( c == 0 ) { return i ; } i -- ; } return - 1 ; } static boolean isBalanced ( char X [ ] , int n ) { int i , j = 0 , k , x , start , end ; for ( i = 0 ; i < n ; i ++ ) { if ( X [ i ] == ' ( ' ) { j = matchClosing ( X , i , n - 1 , ' ( ' , ' ) ' ) ; } else if ( X [ i ] == ' { ' ) { j = matchClosing ( X , i , n - 1 , ' { ' , ' } ' ) ; } else if ( X [ i ] == ' [ ' ) { j = matchClosing ( X , i , n - 1 , ' [ ' , ' ] ' ) ; } else { if ( X [ i ] == ' ) ' ) { j = matchingOpening ( X , 0 , i , ' ( ' , ' ) ' ) ; } else if ( X [ i ] == ' } ' ) { j = matchingOpening ( X , 0 , i , ' { ' , ' } ' ) ; } else if ( X [ i ] == ' ] ' ) { j = matchingOpening ( X , 0 , i , ' [ ' , ' ] ' ) ; } if ( j < 0 j >= i ) { return false ; } continue ; } if ( j >= n j < 0 ) { return false ; } start = i ; end = j ; for ( k = start + 1 ; k < end ; k ++ ) { if ( X [ k ] == ' ( ' ) { x = matchClosing ( X , k , end , ' ( ' , ' ) ' ) ; if ( ! ( k < x && x < end ) ) { return false ; } } else if ( X [ k ] == ' ) ' ) { x = matchingOpening ( X , start , k , ' ( ' , ' ) ' ) ; if ( ! ( start < x && x < k ) ) { return false ; } } if ( X [ k ] == ' { ' ) { x = matchClosing ( X , k , end , ' { ' , ' } ' ) ; if ( ! ( k < x && x < end ) ) { return false ; } } else if ( X [ k ] == ' } ' ) { x = matchingOpening ( X , start , k , ' { ' , ' } ' ) ; if ( ! ( start < x && x < k ) ) { return false ; } } if ( X [ k ] == ' [ ' ) { x = matchClosing ( X , k , end , ' [ ' , ' ] ' ) ; if ( ! ( k < x && x < end ) ) { return false ; } } else if ( X [ k ] == ' ] ' ) { x = matchingOpening ( X , start , k , ' [ ' , ' ] ' ) ; if ( ! ( start < x && x < k ) ) { return false ; } } } } return true ; } public static void main ( String [ ] args ) { char X [ ] = " [ ( ) ] ( ) " . toCharArray ( ) ; int n = 6 ; if ( isBalanced ( X , n ) ) System . out . printf ( "YesNEW_LINE"); else System . out . printf ( "NoNEW_LINE"); char Y [ ] = " [ [ ( ) ] ] ) " . toCharArray ( ) ; n = 7 ; if ( isBalanced ( Y , n ) ) System . out . printf ( "YesNEW_LINE"); else System . out . printf ( "NoNEW_LINE"); } }

Index/key variables: i, k
Accumulator variables: c, i, k
Iterator variables: i, k
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { public static String possibleToSort ( int arr [ ] , int n , String str ) { int max_element = - 1 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { max_element = Math . max ( max_element , arr [ i ] ) ; if ( str . charAt ( i ) == '0' ) { if ( max_element > i + 1 ) return " No " ; } } return " Yes " ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 5 , 3 , 4 , 6 } ; int n = arr . length ; String str = "01110" ; System . out . println ( possibleToSort ( arr , n , str ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findSubstring ( String str , int power ) { HashMap < Integer , Integer > map = new HashMap < > ( ) ; int curr_power = 0 ; int len = str . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { curr_power = curr_power + ( str . charAt ( i ) - ' a ' + 1 ) ; if ( curr_power == power ) { System . out . println ( " Substring ▁ from ▁ index ▁ 0" + " ▁ to ▁ " + i + " ▁ has ▁ power ▁ " + power ) ; return ; } if ( map . containsKey ( curr_power - power ) ) { System . out . println ( " Substring ▁ from ▁ index ▁ " + ( map . get ( curr_power - power ) + 1 ) + " ▁ to ▁ " + i + " ▁ has ▁ power ▁ " + power ) ; return ; } map . put ( curr_power , i ) ; } System . out . println ( " No ▁ substring ▁ with ▁ given ▁ power ▁ exists . " ) ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; int power = 36 ; findSubstring ( str , power ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static boolean isPrimeString ( String str ) { int len = str . length ( ) , n = 0 ; for ( int i = 0 ; i < len ; i ++ ) n += ( int ) str . charAt ( i ) ; if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } public static void main ( String [ ] args ) { String str = " geekRam " ; if ( isPrimeString ( str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: i, n
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int countWays ( String s ) { int count [ ] = new int [ 26 ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) count [ s . charAt ( i ) - ' a ' ] ++ ; count [ s . charAt ( 0 ) - ' a ' ] = 1 ; int ans = 1 ; for ( int i = 0 ; i < 26 ; ++ i ) if ( count [ i ] != 0 ) ans *= count [ i ] ; return ans ; } public static void main ( String ags [ ] ) { String s = " acbbcc " ; System . out . println ( countWays ( s ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void lexoString ( char [ ] s , int k ) { int n = s . length ; Vector < Character > v = new Vector < > ( ) ; Map < Character , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < s . length ; i ++ ) { if ( ! mp . containsKey ( s [ i ] ) ) { mp . put ( s [ i ] , 1 ) ; v . add ( s [ i ] ) ; } } Collections . sort ( v ) ; if ( k > n ) { System . out . print ( String . valueOf ( s ) ) ; for ( int i = n ; i < k ; i ++ ) { System . out . print ( v . get ( 0 ) ) ; } } for ( int i = k - 1 ; i >= 0 ; i -- ) { if ( s [ i ] != v . get ( v . size ( ) - 1 ) ) { for ( int j = 0 ; j < i ; j ++ ) { System . out . print ( s [ j ] ) ; } for ( int j = 0 ; j < v . size ( ) ; j ++ ) { if ( v . get ( j ) > s [ i ] ) { System . out . print ( v . get ( j ) ) ; break ; } } for ( int j = i + 1 ; j < k ; j ++ ) { System . out . print ( v . get ( 0 ) ) ; } return ; } } System . out . print ( " No ▁ lexicographically ▁ greater ▁ string ▁ of ▁ length ▁ " + k + " ▁ possible ▁ here . " ) ; } public static void main ( String arr [ ] ) { String s = " gi " ; int k = 3 ; lexoString ( s . toCharArray ( ) , k ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static final int MAX = 256 ; static long fact ( int n ) { long res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static int countPalinPermutations ( String str ) { int n = str . length ( ) ; int freq [ ] = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ str . charAt ( i ) ] ++ ; long res = fact ( n / 2 ) ; boolean oddFreq = false ; for ( int i = 0 ; i < MAX ; i ++ ) { int half = freq [ i ] / 2 ; if ( freq [ i ] % 2 != 0 ) { if ( oddFreq == true ) return 0 ; oddFreq = true ; } res = res / fact ( half ) ; } return ( int ) res ; } public static void main ( String [ ] args ) { String str = " gffg " ; System . out . print ( countPalinPermutations ( str ) ) ; } }

Index/key variables: MAX, i
Accumulator variables: i
Iterator variables: i
Boolean variables: oddFreq
Class/struct names: GFG
Java program:
import java . util . HashMap ; import java . util . Map . Entry ; class GFG { public static String getPalindrome ( String str ) { HashMap < Character , Integer > counting = new HashMap < > ( ) ; for ( char ch : str . toCharArray ( ) ) { if ( counting . containsKey ( ch ) ) { counting . put ( ch , counting . get ( ch ) + 1 ) ; } else { counting . put ( ch , 1 ) ; } } int oddCount = 0 ; char oddChar = 0 ; for ( Entry < Character , Integer > itr : counting . entrySet ( ) ) { if ( itr . getValue ( ) % 2 != 0 ) { oddCount ++ ; oddChar = itr . getKey ( ) ; } } if ( oddCount > 1 || oddCount == 1 && str . length ( ) % 2 == 0 ) { return " NO ▁ PALINDROME " ; } String firstHalf = " " , lastHalf = " " ; for ( Entry < Character , Integer > itr : counting . entrySet ( ) ) { String ss = " " ; for ( int i = 0 ; i < itr . getValue ( ) / 2 ; i ++ ) { ss += itr . getKey ( ) ; } firstHalf = firstHalf + ss ; lastHalf = ss + lastHalf ; } return ( oddCount == 1 ) ? ( firstHalf + oddChar + lastHalf ) : ( firstHalf + lastHalf ) ; } public static void main ( String [ ] args ) { String str = " mdaam " ; System . out . println ( getPalindrome ( str ) ) ; } }

Accumulator variables: i, oddCount, ss
Iterator variables: ch, i, itr
Class/struct names: GFG
Java program:
class GfG { static boolean isVowel ( char ch ) { return ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) ; } static boolean isCons ( char ch ) { return ( ch != ' a ' && ch != ' e ' && ch != ' i ' && ch != ' o ' && ch != ' u ' ) ; } static int countSpecial ( char [ ] str ) { int len = str . length ; if ( len == 0 ) return 0 ; int co [ ] = new int [ len + 1 ] ; int vo [ ] = new int [ len + 1 ] ; if ( isCons ( str [ len - 1 ] ) == true ) co [ len - 1 ] = 1 ; else vo [ len - 1 ] = 1 ; for ( int i = len - 2 ; i >= 0 ; i -- ) { if ( isCons ( str [ i ] ) == true ) { co [ i ] = co [ i + 1 ] + 1 ; vo [ i ] = vo [ i + 1 ] ; } else { co [ i ] = co [ i + 1 ] ; vo [ i ] = vo [ i + 1 ] + 1 ; } } long ans = 0 ; for ( int i = 0 ; i < len ; i ++ ) { if ( isVowel ( str [ i ] ) ) ans = ans + co [ i + 1 ] ; else ans = ans + vo [ i + 1 ] ; } return ( int ) ans ; } public static void main ( String [ ] args ) { String str = " adceba " ; System . out . println ( countSpecial ( str . toCharArray ( ) ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GfG
Java program:
import java . io . * ; class GFG { static boolean checkPalindrome ( String str ) { int n = str . length ( ) ; int count = 0 ; for ( int i = 0 ; i < n / 2 ; ++ i ) if ( str . charAt ( i ) != str . charAt ( n - i - 1 ) ) ++ count ; return ( count <= 1 ) ; } public static void main ( String [ ] args ) { String str = " abccaa " ; if ( checkPalindrome ( str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int evenDecimalValue ( String str , int n ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == '0' ) { result += ( n - i ) ; } } return result ; } public static void main ( String [ ] args ) { String str = "10010" ; int n = 5 ; System . out . println ( evenDecimalValue ( str , n ) ) ; } }

Accumulator variables: i, result
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int countSubstr ( String s ) { int n = s . length ( ) ; int [ ] auxArr = new int [ n ] ; if ( s . charAt ( 0 ) == '1' ) auxArr [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '1' ) auxArr [ i ] = auxArr [ i - 1 ] + 1 ; else auxArr [ i ] = auxArr [ i - 1 ] ; } int count = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) if ( s . charAt ( i ) == '1' ) count += auxArr [ i ] ; return count ; } public static void main ( String [ ] args ) { String s = "1101" ; System . out . println ( countSubstr ( s ) ) ; } }

Index/key variables: i, n
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . List ; class GFG { public static ArrayList < Integer > findSubstring ( String A , final List < String > B ) { int size_word = B . get ( 0 ) . length ( ) ; int word_count = B . size ( ) ; int size_l = size_word * word_count ; ArrayList < Integer > res = new ArrayList < Integer > ( ) ; int n = A . length ( ) ; if ( size_l > n ) { return res ; } HashMap < String , Integer > hashMap = new HashMap < String , Integer > ( ) ; for ( String word : B ) { hashMap . put ( word , hashMap . getOrDefault ( word , 0 ) + 1 ) ; } for ( int i = 0 ; i <= n - size_l ; i ++ ) { HashMap < String , Integer > tempMap = ( HashMap < String , Integer > ) hashMap . clone ( ) ; int j = i , count = word_count ; while ( j < i + size_l ) { String word = A . substring ( j , j + size_word ) ; if ( ! hashMap . containsKey ( word ) || tempMap . get ( word ) == 0 ) { break ; } else { tempMap . put ( word , tempMap . get ( word ) - 1 ) ; count -- ; } j += size_word ; } if ( count == 0 ) { res . add ( i ) ; } } return res ; } public static void main ( String [ ] args ) { String S = " barfoothefoobarman " ; ArrayList < String > L = new ArrayList < > ( Arrays . asList ( " foo " , " bar " ) ) ; ArrayList < Integer > indices = findSubstring ( S , L ) ; for ( Integer i : indices ) { System . out . println ( i ) ; } } }

Accumulator variables: count, i, j
Iterator variables: i, word
Class/struct names: GFG
Java program:
class GFG { static int MAX = 256 ; static boolean canMakeStr2 ( String str1 , String str2 ) { int [ ] count = new int [ MAX ] ; char [ ] str3 = str1 . toCharArray ( ) ; for ( int i = 0 ; i < str3 . length ; i ++ ) count [ str3 [ i ] ] ++ ; char [ ] str4 = str2 . toCharArray ( ) ; for ( int i = 0 ; i < str4 . length ; i ++ ) { if ( count [ str4 [ i ] ] == 0 ) return false ; count [ str4 [ i ] ] -- ; } return true ; } static public void main ( String [ ] args ) { String str1 = " geekforgeeks " ; String str2 = " for " ; if ( canMakeStr2 ( str1 , str2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: MAX, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void finalPosition ( String move ) { int l = move . length ( ) ; int countUp = 0 , countDown = 0 ; int countLeft = 0 , countRight = 0 ; for ( int i = 0 ; i < l ; i ++ ) { if ( move . charAt ( i ) == ' U ' ) countUp ++ ; else if ( move . charAt ( i ) == ' D ' ) countDown ++ ; else if ( move . charAt ( i ) == ' L ' ) countLeft ++ ; else if ( move . charAt ( i ) == ' R ' ) countRight ++ ; } System . out . println ( " Final ▁ Position : ▁ ( " + ( countRight - countLeft ) + " , ▁ " + ( countUp - countDown ) + " ) " ) ; } public static void main ( String [ ] args ) { String move = " UDDLLRUUUDUURUDDUULLDRRRR " ; finalPosition ( move ) ; } }

Accumulator variables: countDown, countLeft, countRight, countUp, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int maxbalancedprefix ( String str , int n ) { int sum = 0 ; int maxi = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == ' ( ' ) sum += 1 ; else sum -= 1 ; if ( sum < 0 ) break ; if ( sum == 0 ) maxi = i + 1 ; } return maxi ; } public static void main ( String [ ] args ) { String str = " ( ( ( ) ( ) ) ( ) ) ( ( " ; int n = str . length ( ) ; System . out . println ( maxbalancedprefix ( str , n ) ) ; } }

Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int cost ( String str ) { int len = str . length ( ) ; int res = 0 ; for ( int i = 0 , j = len - 1 ; i < j ; i ++ , j -- ) if ( str . charAt ( i ) != str . charAt ( j ) ) res += Math . min ( str . charAt ( i ) , str . charAt ( j ) ) - ' a ' + 1 ; return res ; } public static void main ( String [ ] args ) { String str = " abcdef " ; System . out . println ( cost ( str ) ) ; } }

Accumulator variables: i, j, res
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static boolean isVowel ( char c ) { return ( c == ' A ' c == ' E ' c == ' I ' c == ' O ' c == ' U ' c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) ; } static String pigLatin ( String s ) { int len = s . length ( ) ; int index = - 1 ; for ( int i = 0 ; i < len ; i ++ ) { if ( isVowel ( s . charAt ( i ) ) ) { index = i ; break ; } } if ( index == - 1 ) return " - 1" ; return s . substring ( index ) + s . substring ( 0 , index ) + " ay " ; } public static void main ( String [ ] args ) { String str = pigLatin ( " graphic " ) ; if ( str == " - 1" ) System . out . print ( " No ▁ vowels ▁ found . " + " Pig ▁ Latin ▁ not ▁ possible " ) ; else System . out . print ( str ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; public class GFG { static int MAX_CHAR = 256 ; static boolean isPresent ( String s , String q ) { int [ ] freq = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) freq [ s . charAt ( i ) ] ++ ; for ( int i = 0 ; i < q . length ( ) ; i ++ ) { freq [ q . charAt ( i ) ] -- ; if ( freq [ q . charAt ( i ) ] < 0 ) return false ; } return true ; } static public void main ( String [ ] args ) { String s = " abctd " ; String q = " cat " ; if ( isPresent ( s , q ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: MAX_CHAR
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countReduce ( String str ) { int n = str . length ( ) ; int res = 0 ; for ( int i = 0 ; i < n / 2 ; i ++ ) res += Math . abs ( str . charAt ( i ) - str . charAt ( n - i - 1 ) ) ; return res ; } public static void main ( String [ ] args ) { String str = " abcd " ; System . out . println ( countReduce ( str ) ) ; } }

Accumulator variables: i, res
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int calculate ( String s ) { int ans = 6 ; for ( int i = 0 ; i < 10 ; ++ i ) { for ( int j = 0 ; j < 10 ; ++ j ) { for ( int k = 0 ; k < 10 ; ++ k ) { for ( int l = 0 ; l < 10 ; ++ l ) { for ( int m = 0 ; m < 10 ; ++ m ) { for ( int n = 0 ; n < 10 ; ++ n ) { if ( i + j + k == l + m + n ) { int c = 0 ; if ( i != s . charAt ( 0 ) - '0' ) c ++ ; if ( j != s . charAt ( 1 ) - '0' ) c ++ ; if ( k != s . charAt ( 2 ) - '0' ) c ++ ; if ( l != s . charAt ( 3 ) - '0' ) c ++ ; if ( m != s . charAt ( 4 ) - '0' ) c ++ ; if ( n != s . charAt ( 5 ) - '0' ) c ++ ; if ( c < ans ) ans = c ; } } } } } } } return ans ; } static public void main ( String [ ] args ) { String s = "123456" ; System . out . println ( calculate ( s ) ) ; } }

Accumulator variables: c
Iterator variables: i, j, k, l, m, n
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean makeAndCheckString ( Vector < String > words , String str ) { int n = words . size ( ) ; boolean first = false , second = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( words . get ( i ) == str ) return true ; if ( str . charAt ( 0 ) == words . get ( i ) . charAt ( 1 ) ) first = true ; if ( str . charAt ( 1 ) == words . get ( i ) . charAt ( 0 ) ) second = true ; if ( first && second ) return true ; } return false ; } public static void main ( String [ ] args ) { String str = " ya " ; String [ ] array = { " ah " , " oy " , " to " , " ha " } ; Vector < String > words = new Vector < String > ( Arrays . asList ( array ) ) ; if ( makeAndCheckString ( words , str ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: i
Iterator variables: i
Boolean variables: first, second
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static String getBinaryRep ( int N , int num_of_bits ) { String r = " " ; num_of_bits -- ; while ( num_of_bits >= 0 ) { if ( ( N & ( 1 << num_of_bits ) ) != 0 ) r += "1" ; else r += "0" ; num_of_bits -- ; } return r ; } static ArrayList < String > NBitBinary ( int N ) { ArrayList < String > r = new ArrayList < String > ( ) ; int first = 1 << ( N - 1 ) ; int last = first * 2 ; for ( int i = last - 1 ; i >= first ; -- i ) { int zero_cnt = 0 ; int one_cnt = 0 ; int t = i ; int num_of_bits = 0 ; while ( t > 0 ) { if ( ( t & 1 ) != 0 ) one_cnt ++ ; else zero_cnt ++ ; num_of_bits ++ ; t = t >> 1 ; } if ( one_cnt >= zero_cnt ) { boolean all_prefix_match = true ; int msk = ( 1 << num_of_bits ) - 2 ; int prefix_shift = 1 ; while ( msk > 0 ) { int prefix = ( msk & i ) >> prefix_shift ; int prefix_one_cnt = 0 ; int prefix_zero_cnt = 0 ; while ( prefix > 0 ) { if ( ( prefix & 1 ) != 0 ) prefix_one_cnt ++ ; else prefix_zero_cnt ++ ; prefix = prefix >> 1 ; } if ( prefix_zero_cnt > prefix_one_cnt ) { all_prefix_match = false ; break ; } prefix_shift ++ ; msk = msk & ( msk << 1 ) ; } if ( all_prefix_match ) { r . add ( getBinaryRep ( i , num_of_bits ) ) ; } } } return r ; } public static void main ( String [ ] args ) { int n = 4 ; ArrayList < String > results = NBitBinary ( n ) ; for ( int i = 0 ; i < results . size ( ) ; ++ i ) System . out . print ( results . get ( i ) + " ▁ " ) ; System . out . println ( ) ; } }

Accumulator variables: num_of_bits, one_cnt, prefix_one_cnt, prefix_shift, prefix_zero_cnt, r, zero_cnt
Iterator variables: i
Boolean variables: all_prefix_match
Class/struct names: GFG
Java program:
import java . util . * ; public class ElectoralVotingBallot { public static void findWinner ( String votes [ ] ) { Map < String , Integer > map = new HashMap < String , Integer > ( ) ; for ( String str : votes ) { if ( map . keySet ( ) . contains ( str ) ) map . put ( str , map . get ( str ) + 1 ) ; else map . put ( str , 1 ) ; } int maxValueInMap = 0 ; String winner = " " ; for ( Map . Entry < String , Integer > entry : map . entrySet ( ) ) { String key = entry . getKey ( ) ; Integer val = entry . getValue ( ) ; if ( val > maxValueInMap ) { maxValueInMap = val ; winner = key ; } else if ( val == maxValueInMap && winner . compareTo ( key ) > 0 ) winner = key ; } System . out . println ( winner ) ; } public static void main ( String [ ] args ) { String [ ] votes = { " john " , " johnny " , " jackie " , " johnny " , " john " , " jackie " , " jamie " , " jamie " , " john " , " johnny " , " jamie " , " johnny " , " john " } ; findWinner ( votes ) ; } }

Iterator variables: str
Class/struct names: ElectoralVotingBallot
Java program:
import java . io . * ; class GFG { static boolean checkLuhn ( String cardNo ) { int nDigits = cardNo . length ( ) ; int nSum = 0 ; boolean isSecond = false ; for ( int i = nDigits - 1 ; i >= 0 ; i -- ) { int d = cardNo . charAt ( i ) - '0' ; if ( isSecond == true ) d = d * 2 ; nSum += d / 10 ; nSum += d % 10 ; isSecond = ! isSecond ; } return ( nSum % 10 == 0 ) ; } static public void main ( String [ ] args ) { String cardNo = "79927398713" ; if ( checkLuhn ( cardNo ) ) System . out . println ( " This ▁ is ▁ a ▁ valid ▁ card " ) ; else System . out . println ( " This ▁ is ▁ not ▁ a ▁ valid ▁ card " ) ; } }

Accumulator variables: i, nSum
Iterator variables: i
Boolean variables: isSecond
Class/struct names: GFG
Java program:
import java . io . * ; public class GFG { static int MAX_CHAR = 26 ; static boolean distributingBalls ( long k , long n , String str ) { int [ ] a = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ str . charAt ( i ) - ' a ' ] ++ ; } for ( int i = 0 ; i < MAX_CHAR ; i ++ ) if ( a [ i ] > k ) return false ; return true ; } static public void main ( String [ ] args ) { long n = 6 , k = 3 ; String str = " aacaab " ; if ( distributingBalls ( k , n , str ) ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

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