dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static final int N = 100000 ; static void createHash ( HashSet < Integer > hash , int maxElement ) { int prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr <= maxElement ) { int temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } static int longestFibSubarray ( int arr [ ] , int n ) { int max_val = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; HashSet < Integer > hash = new HashSet < Integer > ( ) ; createHash ( hash , max_val ) ; int [ ] left = new int [ n ] ; int [ ] right = new int [ n ] ; int fibcount = 0 , res = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { left [ i ] = fibcount ; if ( hash . contains ( arr [ i ] ) ) { fibcount ++ ; } else fibcount = 0 ; } fibcount = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { right [ i ] = fibcount ; if ( hash . contains ( arr [ i ] ) ) { fibcount ++ ; } else fibcount = 0 ; } for ( int i = 0 ; i < n ; i ++ ) res = Math . max ( res , left [ i ] + right [ i ] ) ; return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 8 , 5 , 7 , 3 , 5 , 7 } ; int n = arr . length ; System . out . print ( longestFibSubarray ( arr , n ) + "NEW_LINE"); } }

Index/key variables: i, n
Accumulator variables: fibcount, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isPrime ( int N ) { if ( N < 2 ) return false ; if ( N < 4 ) return true ; if ( ( N & 1 ) == 0 ) return false ; if ( N % 3 == 0 ) return false ; int curr = 5 , s = ( int ) Math . sqrt ( N ) ; while ( curr <= s ) { if ( N % curr == 0 ) return false ; curr += 2 ; if ( N % curr == 0 ) return false ; curr += 4 ; } return true ; } static boolean check ( int s , int p , int prefix_sum [ ] , int n ) { boolean satisfies = true ; for ( int i = 0 ; i < n ; i ++ ) { if ( i + s - 1 >= n ) break ; if ( prefix_sum [ i + s - 1 ] - ( i - 1 >= 0 ? prefix_sum [ i - 1 ] : 0 ) < p ) satisfies = false ; } return satisfies ; } static int minimumWindowSize ( int x , int y , int p ) { int [ ] prefix_sum = new int [ y - x + 1 ] ; for ( int i = x ; i <= y ; i ++ ) { if ( isPrime ( i ) ) prefix_sum [ i - x ] = 1 ; } for ( int i = 1 ; i < y - x + 1 ; i ++ ) prefix_sum [ i ] += prefix_sum [ i - 1 ] ; int low = 1 , high = y - x + 1 ; int mid ; while ( high - low > 1 ) { mid = ( low + high ) / 2 ; if ( check ( mid , p , prefix_sum , y - x + 1 ) ) { high = mid ; } else low = mid ; } if ( check ( low , p , prefix_sum , y - x + 1 ) ) return low ; return high ; } public static void main ( String [ ] args ) { int x = 12 ; int y = 42 ; int p = 3 ; System . out . print ( minimumWindowSize ( x , y , p ) ) ; } }

Index/key variables: i
Accumulator variables: curr, i
Iterator variables: i
Boolean variables: satisfies
Class/struct names: GFG
Java program:
class GFG { static int xorOfSum ( int a [ ] , int n ) { int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) answer ^= ( a [ i ] + a [ j ] ) ; } return answer ; } public static void main ( String [ ] args ) { int n = 3 ; int A [ ] = { 1 , 2 , 3 } ; System . out . print ( xorOfSum ( A , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: answer, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static final int N = 4 ; static final int M = 5 ; static void preProcess ( int [ ] [ ] mat , int [ ] [ ] aux ) { for ( int i = 0 ; i < M ; i ++ ) aux [ 0 ] [ i ] = mat [ 0 ] [ i ] ; for ( int i = 1 ; i < N ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) aux [ i ] [ j ] = mat [ i ] [ j ] + aux [ i - 1 ] [ j ] ; for ( int i = 0 ; i < N ; i ++ ) for ( int j = 1 ; j < M ; j ++ ) aux [ i ] [ j ] += aux [ i ] [ j - 1 ] ; } static int sumQuery ( int [ ] [ ] aux , int tli , int tlj , int rbi , int rbj ) { int res = aux [ rbi ] [ rbj ] ; if ( tli > 0 ) res = res - aux [ tli - 1 ] [ rbj ] ; if ( tlj > 0 ) res = res - aux [ rbi ] [ tlj - 1 ] ; if ( tli > 0 && tlj > 0 ) res = res + aux [ tli - 1 ] [ tlj - 1 ] ; return res ; } static int maximumSquareSize ( int [ ] [ ] mat , int K ) { int [ ] [ ] aux = new int [ N ] [ M ] ; preProcess ( mat , aux ) ; for ( int i = Math . min ( N , M ) ; i >= 1 ; i -- ) { boolean satisfies = true ; for ( int x = 0 ; x < N ; x ++ ) { for ( int y = 0 ; y < M ; y ++ ) { if ( x + i - 1 <= N - 1 && y + i - 1 <= M - 1 ) { if ( sumQuery ( aux , x , y , x + i - 1 , y + i - 1 ) > K ) satisfies = false ; } } } if ( satisfies == true ) return ( i ) ; } return 0 ; } public static void main ( String [ ] args ) { int K = 30 ; int mat [ ] [ ] = { { 1 , 2 , 3 , 4 , 6 } , { 5 , 3 , 8 , 1 , 2 } , { 4 , 6 , 7 , 5 , 5 } , { 2 , 4 , 8 , 9 , 4 } } ; System . out . print ( maximumSquareSize ( mat , K ) ) ; } }

Index/key variables: M, N, i, j, rbi, rbj
Accumulator variables: i, j, x, y
Iterator variables: i, j, x, y
Boolean variables: satisfies
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void createHash ( HashSet < Integer > hash , int maxElement ) { int prev = 0 , curr = 1 ; hash . add ( prev ) ; hash . add ( curr ) ; while ( curr < maxElement ) { int temp = curr + prev ; hash . add ( temp ) ; prev = curr ; curr = temp ; } } static void findFibonacciPair ( int n ) { HashSet < Integer > hash = new HashSet < Integer > ( ) ; createHash ( hash , n ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( hash . contains ( i ) && hash . contains ( n - i ) ) { System . out . print ( i + " , ▁ " + ( n - i ) + "NEW_LINE"); return ; } } System . out . print ( "-1NEW_LINE"); } public static void main ( String [ ] args ) { int N = 90 ; findFibonacciPair ( N ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void add_factors ( int n , HashMap < Integer , Integer > mp ) { for ( int i = 1 ; i <= ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { if ( mp . containsKey ( i ) ) mp . put ( i , mp . get ( i ) + 1 ) ; else mp . put ( i , 1 ) ; } else { if ( mp . containsKey ( i ) ) mp . put ( i , mp . get ( i ) + 1 ) ; else mp . put ( i , 1 ) ; if ( mp . containsKey ( n / i ) ) mp . put ( n / i , mp . get ( n / i ) + 1 ) ; else mp . put ( n / i , 1 ) ; } } } } static void count_divisors ( int a [ ] , int n ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( mp . get ( a [ i ] ) == null ? 0 + " ▁ " : mp . get ( a [ i ] ) + " ▁ " ) ; add_factors ( a [ i ] , mp ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 1 , 28 , 4 , 2 , 6 , 7 } ; int n = arr . length ; count_divisors ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void removeDuplicates ( int arr [ ] , int n ) { int st = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i < n - 2 && arr [ i ] == arr [ i + 1 ] && arr [ i ] == arr [ i + 2 ] ) continue ; else { arr [ st ] = arr [ i ] ; st ++ ; } } System . out . print ( " { " ) ; for ( int i = 0 ; i < st ; i ++ ) { System . out . print ( arr [ i ] ) ; if ( i != st - 1 ) System . out . print ( " , ▁ " ) ; } System . out . print ( " } " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 , 2 , 2 , 2 , 3 , 3 , 3 , 3 , 3 , 3 , 4 , 5 } ; int n = arr . length ; removeDuplicates ( arr , n ) ; } }

Index/key variables: i, st
Accumulator variables: i, st
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean permutation ( int [ ] arr , int n ) { Set < Integer > hash = new HashSet < Integer > ( ) ; int maxEle = 0 ; for ( int i = 0 ; i < n ; i ++ ) { hash . add ( arr [ i ] ) ; maxEle = Math . max ( maxEle , arr [ i ] ) ; } if ( maxEle != n ) return false ; if ( hash . size ( ) == n ) return true ; return false ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 5 , 3 , 2 } ; int n = arr . length ; if ( permutation ( arr , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int CountSubSet ( int arr [ ] , int n , int X ) { int N = ( int ) Math . pow ( 2 , n ) ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) != 0 ) if ( arr [ j ] == X ) count += 1 ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 6 , 7 } ; int X = 5 ; int n = arr . length ; System . out . print ( CountSubSet ( arr , n , X ) ) ; } }

Index/key variables: j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int calculatePower ( int b , int e ) { int ans = 1 ; while ( e > 0 ) { if ( e % 2 == 1 ) ans = ans * b ; e = e / 2 ; b = b * b ; } return ans ; } static int CountSubSet ( int arr [ ] , int n , int X ) { int count = 0 , checkX = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == X ) { checkX = 1 ; break ; } } if ( checkX == 1 ) count = calculatePower ( 2 , n - 1 ) ; else count = 0 ; return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 6 , 7 } ; int X = 5 ; int n = arr . length ; System . out . println ( CountSubSet ( arr , n , X ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int [ ] height = new int [ ] { 1 , 2 , 1 , 2 } ; public static int woodCollected ( int n , int m ) { int sum = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( height [ i ] - m <= 0 ) break ; sum += ( height [ i ] - m ) ; } return sum ; } public static int collectKWood ( int n , int k ) { Arrays . sort ( height ) ; int low = 0 , high = height [ n - 1 ] ; while ( low <= high ) { int mid = low + ( ( high - low ) / 2 ) ; int collected = woodCollected ( n , mid ) ; if ( collected == k ) return mid ; if ( collected > k ) low = mid + 1 ; else high = mid - 1 ; } return - 1 ; } public static void main ( String [ ] args ) { int k = 2 ; int n = height . length ; System . out . print ( collectKWood ( n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int MAX = 10 ; static boolean isDigit ( char ch ) { if ( ch >= '0' && ch <= '9' ) return true ; return false ; } static boolean allDigits ( String str , int len ) { boolean [ ] present = new boolean [ MAX ] ; for ( int i = 0 ; i < len ; i ++ ) { if ( isDigit ( str . charAt ( i ) ) ) { int digit = str . charAt ( i ) - '0' ; present [ digit ] = true ; } } for ( int i = 0 ; i < MAX ; i ++ ) { if ( ! present [ i ] ) return false ; } return true ; } public static void main ( String [ ] args ) { String str = " Geeks12345for69708" ; int len = str . length ( ) ; if ( allDigits ( str , len ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Index/key variables: MAX, digit, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isPlusPossible ( int arr [ ] , int n ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } boolean foundModOne = false ; for ( Map . Entry < Integer , Integer > x : mp . entrySet ( ) ) { int element = x . getKey ( ) ; int frequency = x . getValue ( ) ; if ( frequency % 4 == 0 ) continue ; if ( frequency % 4 == 1 ) { if ( foundModOne ) return false ; foundModOne = true ; } else return false ; } return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 , 1 , 2 , 2 , 2 , 3 , 2 } ; int n = arr . length ; if ( isPlusPossible ( arr , n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Boolean variables: foundModOne
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Vector < Integer > merge ( Vector < Integer > v1 , Vector < Integer > v2 ) { int i = 0 , j = 0 ; Vector < Integer > v = new Vector < > ( ) ; while ( i < v1 . size ( ) && j < v2 . size ( ) ) { if ( v1 . elementAt ( i ) <= v2 . elementAt ( j ) ) { v . add ( v1 . elementAt ( i ) ) ; i ++ ; } else { v . add ( v2 . elementAt ( j ) ) ; j ++ ; } } for ( int k = i ; k < v1 . size ( ) ; k ++ ) v . add ( v1 . elementAt ( k ) ) ; for ( int k = j ; k < v2 . size ( ) ; k ++ ) v . add ( v2 . elementAt ( k ) ) ; return v ; } static void buildTree ( Vector < Integer > [ ] tree , int [ ] arr , int index , int s , int e ) { if ( s == e ) { tree [ index ] . add ( arr [ s ] ) ; return ; } int mid = ( s + e ) / 2 ; buildTree ( tree , arr , 2 * index , s , mid ) ; buildTree ( tree , arr , 2 * index + 1 , mid + 1 , e ) ; tree [ index ] = merge ( tree [ 2 * index ] , tree [ 2 * index + 1 ] ) ; } static int query ( Vector < Integer > [ ] tree , int index , int s , int e , int l , int r , int k ) { if ( r < s l > e ) return 0 ; if ( s >= l && e <= r ) { return ( tree [ index ] . size ( ) - lowerBound ( tree [ index ] , tree [ index ] . size ( ) , k ) ) ; } int mid = ( s + e ) / 2 ; return ( query ( tree , 2 * index , s , mid , l , r , k ) + query ( tree , 2 * index + 1 , mid + 1 , e , l , r , k ) ) ; } static void performQueries ( int L [ ] , int R [ ] , int K [ ] , int n , int q , Vector < Integer > tree [ ] ) { for ( int i = 0 ; i < q ; i ++ ) { System . out . println ( query ( tree , 1 , 0 , n - 1 , L [ i ] - 1 , R [ i ] - 1 , K [ i ] ) ) ; } } static int lowerBound ( Vector < Integer > array , int length , int value ) { int low = 0 ; int high = length ; while ( low < high ) { final int mid = ( low + high ) / 2 ; if ( value <= array . elementAt ( mid ) ) { high = mid ; } else { low = mid + 1 ; } } return low ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 3 , 9 , 13 , 5 , 4 } ; int n = arr . length ; @ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] tree = new Vector [ 4 * n + 1 ] ; for ( int i = 0 ; i < ( 4 * n + 1 ) ; i ++ ) { tree [ i ] = new Vector < > ( ) ; } buildTree ( tree , arr , 1 , 0 , n - 1 ) ; int L [ ] = { 1 , 2 } ; int R [ ] = { 4 , 6 } ; int K [ ] = { 6 , 8 } ; int q = L . length ; performQueries ( L , R , K , n , q , tree ) ; } }

Index/key variables: i, index, s
Accumulator variables: i, j, k
Iterator variables: i, k
Class/struct names: GFG
Java program:
public class GFG { int [ ] arr , tree ; int combine ( int a , int b ) { if ( a != 0 && b != 0 ) { return a ; } if ( a >= b ) { return a ; } return b ; } void buildTree ( int ind , int low , int high , int x ) { if ( low == high ) { if ( arr [ low ] > x ) { tree [ ind ] = arr [ low ] ; } else { tree [ ind ] = 0 ; } return ; } int mid = ( high - low ) / 2 + low ; buildTree ( 2 * ind + 1 , low , mid , x ) ; buildTree ( 2 * ind + 2 , mid + 1 , high , x ) ; tree [ ind ] = combine ( tree [ 2 * ind + 1 ] , tree [ 2 * ind + 2 ] ) ; } int query ( int ind , int low , int high , int l , int r ) { int mid = ( high - low ) / 2 + low ; if ( low > r high < l ) { return 0 ; } if ( l <= low && r >= high ) { return tree [ ind ] ; } return combine ( query ( 2 * ind + 1 , low , mid , l , r ) , query ( 2 * ind + 2 , mid + 1 , high , l , r ) ) ; } public static void main ( String args [ ] ) { GFG ob = new GFG ( ) ; ob . arr = new int [ ] { 7 , 3 , 9 , 13 , 5 , 4 } ; int n = ob . arr . length ; int k = 6 ; ob . tree = new int [ 4 * n ] ; int l = 1 , r = 4 ; ob . buildTree ( 0 , 0 , n - 1 , k ) ; System . out . println ( ob . query ( 0 , 0 , n - 1 , l - 1 , r - 1 ) ) ; } }

Index/key variables: ind, low
Class/struct names: GFG
Java program:
class GFG { static int findGCDSum ( int n , int a [ ] ) { int GCDSum = 0 ; int tempGCD = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { tempGCD = 0 ; for ( int k = i ; k <= j ; k ++ ) { tempGCD = __gcd ( tempGCD , a [ k ] ) ; } GCDSum += tempGCD ; } } return GCDSum ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int n = 5 ; int a [ ] = { 1 , 2 , 3 , 4 , 5 } ; int totalSum = findGCDSum ( n , a ) ; System . out . print ( totalSum + "NEW_LINE"); } }

Index/key variables: k
Accumulator variables: GCDSum, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
class GFG { static boolean containsElement ( int [ ] arr , int n ) { int xorArr = 0 ; for ( int i = 0 ; i < n ; ++ i ) xorArr ^= arr [ i ] ; for ( int i = 0 ; i < n ; ++ i ) { int x = xorArr ^ arr [ i ] ; if ( arr [ i ] == x ) return true ; } return false ; } public static void main ( String [ ] args ) { int [ ] arr = { 8 , 2 , 4 , 15 , 1 } ; int n = arr . length ; if ( containsElement ( arr , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i
Accumulator variables: xorArr
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int length_substring ( String S , char K ) { int curr_cnt = 0 , prev_cnt = 0 , max_len ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( S . charAt ( i ) == K ) { curr_cnt += 1 ; } else { prev_cnt = Math . max ( prev_cnt , curr_cnt ) ; curr_cnt = 0 ; } } prev_cnt = Math . max ( prev_cnt , curr_cnt ) ; max_len = prev_cnt ; return max_len ; } public static void main ( String [ ] args ) { String S = " abcd1111aabc " ; char K = '1' ; System . out . print ( length_substring ( S , K ) ) ; } }

Accumulator variables: curr_cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static int Xor_Sum ( int [ ] arr , int n ) { int sum = 0 , index = - 1 ; int left_xor = 0 , right_xor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { left_xor = left_xor ^ arr [ i ] ; right_xor = 0 ; for ( int j = i + 1 ; j < n ; j ++ ) { right_xor = right_xor ^ arr [ j ] ; } if ( left_xor + right_xor > sum ) { sum = left_xor + right_xor ; index = i ; } } return index + 1 ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 } ; int n = arr . length ; System . out . println ( Xor_Sum ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void ComputePrefixXor ( int arr [ ] , int PrefixXor [ ] , int n ) { PrefixXor [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) PrefixXor [ i ] = PrefixXor [ i - 1 ] ^ arr [ i ] ; } static int Xor_Sum ( int arr [ ] , int n ) { int [ ] PrefixXor = new int [ n ] ; ComputePrefixXor ( arr , PrefixXor , n ) ; int sum = 0 , index = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) > sum ) { sum = PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) ; index = i ; } } return index + 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 } ; int n = arr . length ; System . out . println ( Xor_Sum ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static final int ALPHABET_SIZE = 26 ; static class TrieNode { TrieNode [ ] children ; boolean isEndOfWord ; TrieNode ( ) { this . children = new TrieNode [ ALPHABET_SIZE ] ; } } static TrieNode getNode ( ) { TrieNode pNode = new TrieNode ( ) ; pNode . isEndOfWord = false ; Arrays . fill ( pNode . children , null ) ; return pNode ; } static void insert ( TrieNode root , String key ) { TrieNode pCrawl = root ; for ( int i = 0 ; i < key . length ( ) ; i ++ ) { int index = key . charAt ( i ) - ' a ' ; if ( pCrawl . children [ index ] == null ) pCrawl . children [ index ] = getNode ( ) ; pCrawl . isEndOfWord = false ; pCrawl = pCrawl . children [ index ] ; } int i ; for ( i = 0 ; i < 26 ; i ++ ) { if ( pCrawl . children [ i ] != null ) { break ; } } if ( i == 26 ) { pCrawl . isEndOfWord = true ; } } static void display ( TrieNode root , char str [ ] , int level ) { if ( root . isEndOfWord ) { str [ level ] = ' \0' ; System . out . println ( str ) ; } int i ; for ( i = 0 ; i < ALPHABET_SIZE ; i ++ ) { if ( root . children [ i ] != null ) { str [ level ] = ( char ) ( i + ' a ' ) ; display ( root . children [ i ] , str , level + 1 ) ; } } } public static void main ( String [ ] args ) { String keys [ ] = { " apple " , " app " , " there " , " the " , " like " } ; int n = keys . length ; TrieNode root = getNode ( ) ; for ( int i = 0 ; i < n ; i ++ ) insert ( root , keys [ i ] ) ; char [ ] str = new char [ 100 ] ; display ( root , str , 0 ) ; } }

Index/key variables: ALPHABET_SIZE, i, index, level
Accumulator variables: i
Iterator variables: i
Boolean variables: isEndOfWord
Class/struct names: GFG, TrieNode
Java program:
import java . util . * ; class GFG { static int findColor ( HashMap < Integer , Integer > mapWithColor , int query ) { int maximum = 0 ; while ( query >= 1 ) { if ( mapWithColor . containsKey ( query ) ) { maximum = Math . max ( maximum , mapWithColor . get ( query ) ) ; } if ( query % 2 == 1 ) query = ( query - 1 ) / 2 ; else query = query / 2 ; } return maximum ; } static HashMap < Integer , Integer > buildMapWithColor ( int arr [ ] , int n ) { HashMap < Integer , Integer > mapWithColor = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mapWithColor . put ( arr [ i ] , i + 1 ) ; } return mapWithColor ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 1 , 3 } ; int n = arr . length ; int k = 7 ; HashMap < Integer , Integer > mapWithColor = buildMapWithColor ( arr , n ) ; System . out . print ( findColor ( mapWithColor , k ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX = 26 ; static Vector < Integer > findCount ( String a [ ] , String b [ ] , int n , int m ) { int [ ] freq = new int [ MAX ] ; Vector < Integer > smallestFreq = new Vector < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = a [ i ] ; Arrays . fill ( freq , 0 ) ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { freq [ s . charAt ( j ) - ' a ' ] ++ ; } for ( int j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { smallestFreq . add ( freq [ j ] ) ; break ; } } } Collections . sort ( smallestFreq ) ; Vector < Integer > ans = new Vector < Integer > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { String s = b [ i ] ; Arrays . fill ( freq , 0 ) ; for ( int j = 0 ; j < s . length ( ) ; j ++ ) { freq [ s . charAt ( j ) - ' a ' ] ++ ; } int frequency = 0 ; for ( int j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { frequency = freq [ j ] ; break ; } } int [ ] array = new int [ smallestFreq . size ( ) ] ; int k = 0 ; for ( Integer val : smallestFreq ) { array [ k ] = val ; k ++ ; } int ind = lower_bound ( array , 0 , smallestFreq . size ( ) , frequency ) ; ans . add ( ind ) ; } return ans ; } static int lower_bound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } static void printAnswer ( String a [ ] , String b [ ] , int n , int m ) { Vector < Integer > ans = findCount ( a , b , n , m ) ; for ( Integer it : ans ) { System . out . print ( it + " ▁ " ) ; } } public static void main ( String [ ] args ) { String A [ ] = { " aaa " , " aa " , " bdc " } ; String B [ ] = { " cccch " , " cccd " } ; int n = A . length ; int m = B . length ; printAnswer ( A , B , n , m ) ; } }

Index/key variables: MAX, i, j, k, middle
Accumulator variables: i, j, k
Iterator variables: i, it, j, val
Class/struct names: GFG