dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . regex . * ; class GFG { public static boolean isValidPinCode ( String pinCode ) { String regex = " ^ [ 1-9 ] { 1 } [ 0-9 ] { 2 } \\ s { 0,1 } [ 0-9 ] { 3 } $ " ; Pattern p = Pattern . compile ( regex ) ; if ( pinCode == null ) { return false ; } Matcher m = p . matcher ( pinCode ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String num1 = "132103" ; System . out . println ( num1 + " : ▁ " + isValidPinCode ( num1 ) ) ; String num2 = "201 ▁ 305" ; System . out . println ( num2 + " : ▁ " + isValidPinCode ( num2 ) ) ; String num3 = "014205" ; System . out . println ( num3 + " : ▁ " + isValidPinCode ( num3 ) ) ; String num4 = "1473598" ; System . out . println ( num4 + " : ▁ " + isValidPinCode ( num4 ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . regex . * ; class GFG { public static boolean isValidTime ( String time ) { String regex = " ( [01 ] ? [0-9 ] ▁ 2[0-3 ] ) : [ 0-5 ] [ 0-9 ] " ; Pattern p = Pattern . compile ( regex ) ; if ( time == null ) { return false ; } Matcher m = p . matcher ( time ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = "13:05" ; System . out . println ( str1 + " : ▁ " + isValidTime ( str1 ) ) ; String str2 = "02:15" ; System . out . println ( str2 + " : ▁ " + isValidTime ( str2 ) ) ; String str3 = "24:00" ; System . out . println ( str3 + " : ▁ " + isValidTime ( str3 ) ) ; String str4 = "10:60" ; System . out . println ( str4 + " : ▁ " + isValidTime ( str4 ) ) ; String str5 = "10:15 ▁ PM " ; System . out . println ( str5 + " : ▁ " + isValidTime ( str5 ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . regex . * ; class GFG { public static boolean isValidHexaCode ( String str ) { String regex = " ^ # ( [ A - Fa - f0-9 ] { 6 } ▁ [ A - Fa - f0-9 ] { 3 } ) $ " ; Pattern p = Pattern . compile ( regex ) ; if ( str == null ) { return false ; } Matcher m = p . matcher ( str ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = " # 1AFFa1" ; System . out . println ( str1 + " : ▁ " + isValidHexaCode ( str1 ) ) ; String str2 = " # F00" ; System . out . println ( str2 + " : ▁ " + isValidHexaCode ( str2 ) ) ; String str3 = "123456" ; System . out . println ( str3 + " : ▁ " + isValidHexaCode ( str3 ) ) ; String str4 = " # 123abce " ; System . out . println ( str4 + " : ▁ " + isValidHexaCode ( str4 ) ) ; String str5 = " # afafah " ; System . out . println ( str5 + " : ▁ " + isValidHexaCode ( str5 ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . regex . * ; class GFG { public static boolean isValidPanCardNo ( String panCardNo ) { String regex = " [ A - Z ] { 5 } [ 0-9 ] { 4 } [ A - Z ] { 1 } " ; Pattern p = Pattern . compile ( regex ) ; if ( panCardNo == null ) { return false ; } Matcher m = p . matcher ( panCardNo ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = " BNZAA2318J " ; System . out . println ( isValidPanCardNo ( str1 ) ) ; String str2 = "23ZAABN18J " ; System . out . println ( isValidPanCardNo ( str2 ) ) ; String str3 = " BNZAA2318JM " ; System . out . println ( isValidPanCardNo ( str3 ) ) ; String str4 = " BNZAA23184" ; System . out . println ( isValidPanCardNo ( str4 ) ) ; String str5 = " BNZAA ▁ 23184" ; System . out . println ( isValidPanCardNo ( str5 ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . regex . * ; class GFG { public static boolean isValidTime ( String time ) { String regexPattern = " ( 1[012 ] ▁ [ 1-9 ] ) : " + " [ 0-5 ] [ 0-9 ] ( \\ s ) " + " ? ( ? i ) ( am ▁ pm ) " ; Pattern compiledPattern = Pattern . compile ( regexPattern ) ; if ( time == null ) { return false ; } Matcher m = compiledPattern . matcher ( time ) ; return m . matches ( ) ; } public static void main ( String args [ ] ) { String str1 = "12:15 ▁ AM " ; System . out . println ( isValidTime ( str1 ) ) ; String str2 = "9:45PM " ; System . out . println ( isValidTime ( str2 ) ) ; String str3 = "1:15" ; System . out . println ( isValidTime ( str3 ) ) ; String str4 = "17:30" ; System . out . println ( isValidTime ( str4 ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class Count_Flips { public static int count_flips ( int a [ ] , int n , int k ) { boolean set = false ; int ans = 0 , min_diff = Integer . MAX_VALUE ; for ( int i = 0 ; i < k ; i ++ ) { int curr_index = i , segment = 0 , count_zero = 0 , count_one = 0 ; while ( curr_index < n ) { if ( segment % 2 == 0 ) { if ( a [ curr_index ] == 1 ) count_zero ++ ; else count_one ++ ; } else { if ( a [ curr_index ] == 0 ) count_zero ++ ; else count_one ++ ; } curr_index = curr_index + k ; segment ++ ; } ans += Math . min ( count_one , count_zero ) ; if ( count_one < count_zero ) set = ! set ; min_diff = Math . min ( min_diff , Math . abs ( count_zero - count_one ) ) ; } if ( set ) return ans ; else return ans + min_diff ; } public static void main ( String [ ] args ) { int n = 6 , k = 3 ; int a [ ] = { 0 , 0 , 1 , 1 , 0 , 0 } ; System . out . println ( count_flips ( a , n , k ) ) ; } }

Index/key variables: curr_index
Accumulator variables: ans, count_one, count_zero, i, segment
Iterator variables: i
Boolean variables: set
Class/struct names: Count_Flips
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; Node ( int data ) { this . data = data ; this . left = this . right = null ; } } ; static int size ( Node node ) { if ( node == null ) return 0 ; else return ( size ( node . left ) + 1 + size ( node . right ) ) ; } static boolean checkIsAP ( double [ ] arr , int n ) { if ( n == 1 ) return true ; Arrays . sort ( arr ) ; double d = arr [ 1 ] - arr [ 0 ] ; for ( int i = 2 ; i < n ; i ++ ) if ( arr [ i ] - arr [ i - 1 ] != d ) return false ; return true ; } static boolean checkIsGP ( double [ ] arr , int n ) { if ( n == 1 ) return true ; Arrays . sort ( arr ) ; double r = arr [ 1 ] / arr [ 0 ] ; for ( int i = 2 ; i < n ; i ++ ) { if ( arr [ i ] / arr [ i - 1 ] != r ) return false ; } return true ; } static boolean checkIsHP ( double [ ] arr , int n ) { if ( n == 1 ) { return true ; } double [ ] rec = new double [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { rec [ i ] = ( ( 1 / arr [ i ] ) ) ; } Arrays . sort ( rec ) ; double d = ( rec [ 1 ] ) - ( rec [ 0 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { if ( rec [ i ] - rec [ i - 1 ] != d ) { return false ; } } return true ; } static void checktype ( Node root ) { int n = size ( root ) ; double [ ] arr = new double [ n ] ; int i = 0 ; if ( root == null ) return ; Queue < Node > q = new LinkedList < > ( ) ; q . add ( root ) ; while ( q . isEmpty ( ) == false ) { Node node = q . poll ( ) ; arr [ i ] = node . data ; i ++ ; if ( node . left != null ) q . add ( node . left ) ; if ( node . right != null ) q . add ( node . right ) ; } int flag = 0 ; if ( checkIsAP ( arr , n ) ) { System . out . println ( " Arithmetic ▁ Progression " ) ; flag = 1 ; } else if ( checkIsGP ( arr , n ) ) { System . out . println ( " Geometric ▁ Progression " ) ; flag = 1 ; } else if ( checkIsHP ( arr , n ) ) { System . out . println ( " Geometric ▁ Progression " ) ; flag = 1 ; } else if ( flag == 0 ) { System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . right = new Node ( 8 ) ; root . right . right . left = new Node ( 6 ) ; root . right . right . right = new Node ( 7 ) ; checktype ( root ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
Java program:
class GFG { static void q1 ( String s , int i ) { System . out . print ( " q1 - > " ) ; if ( i == s . length ( ) ) { System . out . println ( " NO " ) ; return ; } if ( s . charAt ( i ) == '0' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q2 ( String s , int i ) { System . out . print ( " q2 - > " ) ; if ( i == s . length ( ) ) { System . out . println ( " NO ▁ " ) ; return ; } if ( s . charAt ( i ) == '0' ) q4 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q3 ( String s , int i ) { System . out . print ( " q3 - > " ) ; if ( i == s . length ( ) ) { System . out . println ( " YES " ) ; return ; } if ( s . charAt ( i ) == '0' ) q4 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } static void q4 ( String s , int i ) { System . out . print ( " q4 - > " ) ; if ( i == s . length ( ) ) { System . out . println ( " YES " ) ; return ; } if ( s . charAt ( i ) == '0' ) q1 ( s , i + 1 ) ; else q3 ( s , i + 1 ) ; } static void q0 ( String s , int i ) { System . out . print ( " q0 - > " ) ; if ( i == s . length ( ) ) { System . out . println ( " NO " ) ; return ; } if ( s . charAt ( i ) == '0' ) q1 ( s , i + 1 ) ; else q2 ( s , i + 1 ) ; } public static void main ( String [ ] args ) { String s = "010101" ; System . out . print ( " State ▁ transitions ▁ are ▁ " ) ; q0 ( s , 0 ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static boolean checkSequence ( String a , String b ) { if ( b . length ( ) == 0 ) return true ; if ( a . length ( ) == 0 ) return false ; if ( a . charAt ( 0 ) == b . charAt ( 0 ) ) return checkSequence ( a . substring ( 1 ) , b . substring ( 1 ) ) ; else return checkSequence ( a . substring ( 1 ) , b ) ; } public static void main ( String [ ] args ) { String s1 = " Geeks " , s2 = " Geks " ; if ( checkSequence ( s1 , s2 ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; public class GfG { public static int doMatch ( String A , String B ) { for ( int i = 0 ; i < A . length ( ) ; i ++ ) { if ( A . charAt ( i ) != ' * ' && B . charAt ( i ) != ' * ' ) { if ( A . charAt ( i ) != B . charAt ( i ) ) return 0 ; } } return 1 ; } public static void main ( String [ ] args ) { String A = " gee * sforgeeks " ; String B = " geeksforgeeks " ; System . out . println ( doMatch ( A , B ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GfG
Java program:
import java . util . * ; class GFG { static int countSubstrs ( String s1 , String s2 ) { int ans = 0 ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { String s3 = " " ; char [ ] s4 = s1 . toCharArray ( ) ; for ( int j = i ; j < s1 . length ( ) ; j ++ ) { s3 += s4 [ j ] ; if ( s2 . indexOf ( s3 ) != - 1 ) ans ++ ; } } return ans ; } public static void main ( String [ ] args ) { String s1 = " aab " , s2 = " aaaab " ; System . out . println ( countSubstrs ( s1 , s2 ) ) ; } }

Index/key variables: j
Accumulator variables: ans, i, j, s3
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int factorial ( int N ) { int fact = 1 ; for ( int i = 1 ; i <= N ; i ++ ) fact = fact * i ; return fact ; } static int nthTerm ( int N ) { return ( factorial ( N ) * ( N + 2 ) / 2 ) ; } public static void main ( String args [ ] ) { int N = 6 ; System . out . println ( nthTerm ( N ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int sum = 0 , max_level = Integer . MIN_VALUE ; static class Node { int d ; Node l ; Node r ; } ; static Node createNode ( int d ) { Node node ; node = new Node ( ) ; node . d = d ; node . l = null ; node . r = null ; return node ; } static void sumOfNodesAtMaxDepth ( Node ro , int level ) { if ( ro == null ) return ; if ( level > max_level ) { sum = ro . d ; max_level = level ; } else if ( level == max_level ) { sum = sum + ro . d ; } sumOfNodesAtMaxDepth ( ro . l , level + 1 ) ; sumOfNodesAtMaxDepth ( ro . r , level + 1 ) ; } public static void main ( String [ ] args ) { Node root ; root = createNode ( 1 ) ; root . l = createNode ( 2 ) ; root . r = createNode ( 3 ) ; root . l . l = createNode ( 4 ) ; root . l . r = createNode ( 5 ) ; root . r . l = createNode ( 6 ) ; root . r . r = createNode ( 7 ) ; sumOfNodesAtMaxDepth ( root , 0 ) ; System . out . println ( sum ) ; } }

Class/struct names: GFG, Node
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { public static boolean regexMatch ( String text , String pat ) { int lenText = text . length ( ) ; int lenPat = pat . length ( ) ; char [ ] Text = text . toCharArray ( ) ; char [ ] Pat = pat . toCharArray ( ) ; int i = 0 , j = 0 ; while ( i < lenPat ) { if ( Pat [ i ] != ' # ' ) { if ( Pat [ i ] != Text [ j ] ) return false ; i ++ ; j ++ ; } else { j ++ ; while ( Text [ j ] != Pat [ i + 1 ] ) j ++ ; i ++ ; } } return ( j == lenText ) ; } public static void main ( String [ ] args ) { String str = " ABABABA " ; String pat = " A # B # A " ; if ( regexMatch ( str , pat ) ) System . out . println ( " yes " ) ; else System . out . println ( " no " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void translate ( char str [ ] ) { int len = str . length ; if ( len < 2 ) return ; int i = 0 ; int j = 0 ; while ( j < len - 1 ) { if ( str [ j ] == ' A ' && str [ j + 1 ] == ' B ' ) { j = j + 2 ; str [ i ++ ] = ' C ' ; continue ; } str [ i ++ ] = str [ j ++ ] ; } if ( j == len - 1 ) str [ i ++ ] = str [ j ] ; str [ i ] = ' ▁ ' ; str [ len - 1 ] = ' ▁ ' ; } public static void main ( String args [ ] ) { String st = " helloABworldABGfG " ; char str [ ] = st . toCharArray ( ) ; translate ( str ) ; System . out . println ( " The ▁ modified ▁ string ▁ is ▁ : " ) ; System . out . println ( str ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int R , C ; static int [ ] x = { - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 } ; static int [ ] y = { - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 } ; static boolean search2D ( char [ ] [ ] grid , int row , int col , String word ) { if ( grid [ row ] [ col ] != word . charAt ( 0 ) ) return false ; int len = word . length ( ) ; for ( int dir = 0 ; dir < 8 ; dir ++ ) { int k , rd = row + x [ dir ] , cd = col + y [ dir ] ; for ( k = 1 ; k < len ; k ++ ) { if ( rd >= R rd < 0 cd >= C cd < 0 ) break ; if ( grid [ rd ] [ cd ] != word . charAt ( k ) ) break ; rd += x [ dir ] ; cd += y [ dir ] ; } if ( k == len ) return true ; } return false ; } static void patternSearch ( char [ ] [ ] grid , String word ) { for ( int row = 0 ; row < R ; row ++ ) { for ( int col = 0 ; col < C ; col ++ ) { if ( search2D ( grid , row , col , word ) ) System . out . println ( " pattern ▁ found ▁ at ▁ " + row + " , ▁ " + col ) ; } } } public static void main ( String args [ ] ) { R = 3 ; C = 13 ; char [ ] [ ] grid = { { ' G ' , ' E ' , ' E ' , ' K ' , ' S ' , ' F ' , ' O ' , ' R ' , ' G ' , ' E ' , ' E ' , ' K ' , ' S ' } , { ' G ' , ' E ' , ' E ' , ' K ' , ' S ' , ' Q ' , ' U ' , ' I ' , ' Z ' , ' G ' , ' E ' , ' E ' , ' K ' } , { ' I ' , ' D ' , ' E ' , ' Q ' , ' A ' , ' P ' , ' R ' , ' A ' , ' C ' , ' T ' , ' I ' , ' C ' , ' E ' } } ; patternSearch ( grid , " GEEKS " ) ; System . out . println ( ) ; patternSearch ( grid , " EEE " ) ; } }

Index/key variables: cd, col, dir, rd, row
Accumulator variables: cd, col, dir, k, rd, row
Iterator variables: col, dir, k, row
Class/struct names: GFG
Java program:
class AWQ { static int NO_OF_CHARS = 256 ; static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static void badCharHeuristic ( char [ ] str , int size , int badchar [ ] ) { for ( int i = 0 ; i < NO_OF_CHARS ; i ++ ) badchar [ i ] = - 1 ; for ( int i = 0 ; i < size ; i ++ ) badchar [ ( int ) str [ i ] ] = i ; } static void search ( char txt [ ] , char pat [ ] ) { int m = pat . length ; int n = txt . length ; int badchar [ ] = new int [ NO_OF_CHARS ] ; badCharHeuristic ( pat , m , badchar ) ; int s = 0 ; while ( s <= ( n - m ) ) { int j = m - 1 ; while ( j >= 0 && pat [ j ] == txt [ s + j ] ) j -- ; if ( j < 0 ) { System . out . println ( " Patterns ▁ occur ▁ at ▁ shift ▁ = ▁ " + s ) ; s += ( s + m < n ) ? m - badchar [ txt [ s + m ] ] : 1 ; } else s += max ( 1 , j - badchar [ txt [ s + j ] ] ) ; } } public static void main ( String [ ] args ) { char txt [ ] = " ABAAABCD " . toCharArray ( ) ; char pat [ ] = " ABC " . toCharArray ( ) ; search ( txt , pat ) ; } }

Index/key variables: NO_OF_CHARS, i, j
Accumulator variables: i, j, s
Iterator variables: i
Class/struct names: AWQ
Java program:
import java . util . * ; class Node { int data ; Node left , right ; public Node ( int data ) { this . data = data ; this . left = null ; this . right = null ; } } class GfG { public static int sumMaxLevelRec ( Node node , int max ) { if ( node == null ) return 0 ; if ( max == 1 ) return node . data ; return sumMaxLevelRec ( node . left , max - 1 ) + sumMaxLevelRec ( node . right , max - 1 ) ; } public static int maxDepth ( Node node ) { if ( node == null ) return 0 ; return 1 + Math . max ( maxDepth ( node . left ) , maxDepth ( node . right ) ) ; } public static int sumMaxLevel ( Node root ) { int MaxDepth = maxDepth ( root ) ; return sumMaxLevelRec ( root , MaxDepth ) ; } public static void main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; System . out . println ( sumMaxLevel ( root ) ) ; } }

Class/struct names: GfG, Node
Java program:
import java . lang . * ; import java . util . * ; class GFG { static void SumofDistances ( String s ) { ArrayList < ArrayList < Integer > > v = new ArrayList < > ( ) ; for ( int i = 0 ; i < 26 ; i ++ ) v . add ( new ArrayList < > ( ) ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { v . get ( s . charAt ( i ) - ' a ' ) . add ( i ) ; } int ans = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < v . get ( i ) . size ( ) ; j ++ ) { sum += v . get ( i ) . get ( j ) ; } for ( int j = 0 ; j < v . get ( i ) . size ( ) ; j ++ ) { sum -= v . get ( i ) . get ( j ) ; ans += ( sum - ( v . get ( i ) . size ( ) - 1 - j ) * ( v . get ( i ) . get ( j ) ) ) ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { String s = " ababa " ; SumofDistances ( s ) ; } }

Accumulator variables: ans, i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findOperations ( String A , String B , int N ) { int operations = 0 ; Vector < Integer > ops = new Vector < > ( ) ; boolean invert = false ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( A . charAt ( i ) != B . charAt ( i ) ) { if ( ! invert ) { operations ++ ; ops . add ( i + 1 ) ; invert = true ; } } else { if ( invert ) { operations ++ ; ops . add ( i + 1 ) ; invert = false ; } } } System . out . print ( operations + "NEW_LINE"); if ( operations != 0 ) { for ( int x : ops ) System . out . print ( x + " ▁ " ) ; } } public static void main ( String [ ] args ) { String A = "001" , B = "000" ; int N = A . length ( ) ; findOperations ( A , B , N ) ; } }

Accumulator variables: i, operations
Iterator variables: i, x
Boolean variables: invert
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int maxScoreWords ( String [ ] words , char [ ] letters , int [ ] score ) { int [ ] letterCounts = new int [ 26 ] ; for ( char letter : letters ) letterCounts [ letter - ' a ' ] ++ ; return helper ( words , 0 , letterCounts , score ) ; } public static int helper ( String [ ] words , int start , int [ ] letterCounts , int [ ] score ) { if ( start == words . length ) return 0 ; int currScore = 0 ; int wordScore = 0 ; int [ ] nextCounts = letterCounts . clone ( ) ; for ( int i = 0 ; i < words [ start ] . length ( ) ; ++ i ) { int idx = words [ start ] . charAt ( i ) - ' a ' ; if ( nextCounts [ idx ] == 0 ) { wordScore = - 1 ; break ; } wordScore += score [ idx ] ; nextCounts [ idx ] -- ; } if ( wordScore > 0 ) currScore = helper ( words , start + 1 , nextCounts , score ) + wordScore ; currScore = Math . max ( currScore , helper ( words , start + 1 , letterCounts , score ) ) ; return currScore ; } public static void main ( String [ ] args ) { String words [ ] = { " dog " , " cat " , " dad " , " good " } ; char letters [ ] = { ' a ' , ' a ' , ' c ' , ' d ' , ' d ' , ' d ' , ' g ' , ' o ' , ' o ' } ; int score [ ] = { 1 , 0 , 9 , 5 , 0 , 0 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 } ; System . out . println ( maxScoreWords ( words , letters , score ) ) ; } }

Index/key variables: idx, start
Accumulator variables: wordScore
Iterator variables: i, letter
Class/struct names: GFG
Java program:
class GFG { static void countFrequency ( String S , int N ) { int [ ] freq = new int [ 26 ] ; Array . Clear ( freq , 0 , freq . Length ) ; for ( int i = 0 ; i < N ; i ++ ) { freq [ ( int ) S . charAt ( i ) - ' a ' ] += 1 ; } for ( int i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] == 0 ) continue ; int lg = ( int ) ( Math . log ( freq [ i ] ) / Math . log ( 2 ) ) ; int a = ( int ) Math . pow ( 2 , lg ) ; if ( a == freq [ i ] ) { while ( freq [ i ] > 0 ) { freq [ i ] -= 1 ; System . out . print ( ( char ) ( i + ' a ' ) ) ; } } } } public static void main ( String args [ ] ) { String S = " aaacbb " ; int N = S . length ( ) ; countFrequency ( S , N ) ; } }

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