dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; class GFG { static int countCandies ( int arr [ ] , int n ) { int sum = 0 ; int [ ] ans = new int [ n ] ; if ( n == 1 ) { return 1 ; } for ( int i = 0 ; i < n ; i ++ ) ans [ i ] = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i + 1 ] > arr [ i ] && ans [ i + 1 ] <= ans [ i ] ) { ans [ i + 1 ] = ans [ i ] + 1 ; } } for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] > arr [ i + 1 ] && ans [ i ] <= ans [ i + 1 ] ) { ans [ i ] = ans [ i + 1 ] + 1 ; } else if ( arr [ i ] == arr [ i + 1 ] && ans [ i ] < ans [ i + 1 ] ) { ans [ i ] = ans [ i + 1 ] + 1 ; } sum += ans [ i ] ; } sum += ans [ n - 1 ] ; return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 2 } ; int N = arr . length ; System . out . println ( countCandies ( arr , N ) ) ; } }

Index/key variables: i, n
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findMaximumProfit ( int [ ] arr , int M , int N ) { PriorityQueue < Integer > max_heap = new PriorityQueue < > ( ( a , b ) -> b - a ) ; int maxProfit = 0 ; for ( int i = 0 ; i < N ; i ++ ) max_heap . add ( arr [ i ] ) ; while ( M > 0 ) { M -- ; int X = max_heap . poll ( ) ; maxProfit += X ; max_heap . add ( X - 1 ) ; } System . out . println ( maxProfit ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 4 , 6 } ; int M = 4 ; int N = arr . length ; findMaximumProfit ( arr , M , N ) ; } }

Index/key variables: i
Accumulator variables: M, i, maxProfit
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static void findSequence ( int n , int k ) { int [ ] arr = new int [ n ] ; int sumPos = 0 , sumNeg = 0 ; for ( int i = 0 ; i < n - k ; i ++ ) { arr [ i ] = - ( i + 1 ) ; sumNeg += arr [ i ] ; } for ( int i = n - k ; i < n ; i ++ ) { arr [ i ] = i + 1 ; sumPos += arr [ i ] ; } if ( Math . abs ( sumNeg ) >= sumPos ) { System . out . print ( - 1 ) ; return ; } for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String args [ ] ) { int N = 10 , K = 6 ; findSequence ( N , K ) ; } }

Index/key variables: i, n
Accumulator variables: i, sumNeg, sumPos
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findPath ( int [ ] [ ] arr , int M , int N ) { for ( int row = 0 ; row < M ; row ++ ) { char dir = ' L ' ; int i = row ; int j = 0 ; while ( j < N ) { if ( arr [ i ] [ j ] == 1 ) { if ( dir == ' L ' ) { i -- ; dir = ' D ' ; } else if ( dir == ' U ' ) { j -- ; dir = ' R ' ; } else if ( dir == ' R ' ) { i ++ ; dir = ' U ' ; } else if ( dir == ' D ' ) { j ++ ; dir = ' L ' ; } } else { if ( dir == ' L ' ) { i ++ ; dir = ' U ' ; } else if ( dir == ' U ' ) { j ++ ; dir = ' L ' ; } else if ( dir == ' R ' ) { i -- ; dir = ' D ' ; } else if ( dir == ' D ' ) { j -- ; dir = ' R ' ; } } if ( i < 0 i == M j < 0 j == N ) break ; } if ( j == N ) System . out . print ( i + " ▁ " ) ; else System . out . print ( - 1 + " ▁ " ) ; } } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 1 , 1 , 0 , 1 } , { 1 , 1 , 0 , 0 } , { 1 , 0 , 0 , 0 } , { 1 , 1 , 0 , 1 } , { 0 , 1 , 0 , 1 } } ; int M = arr . length ; int N = arr [ 0 ] . length ; findPath ( arr , M , N ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, row
Iterator variables: row
Class/struct names: GFG
Java program:
class GFG { static int getSum ( int n ) { int ans = 0 ; char [ ] arr = ( String . valueOf ( n ) ) . toCharArray ( ) ; for ( char ch : arr ) { ans += Character . getNumericValue ( ch ) ; } return ans ; } static void getMax ( int [ ] arr ) { int maxRem0 = 0 ; int rem1 = 0 ; int rem2 = 0 ; for ( int i : arr ) { int digitSum = getSum ( i ) ; if ( digitSum % 3 == 0 ) maxRem0 = Math . max ( maxRem0 , i ) ; else if ( digitSum % 3 == 1 ) rem1 += i ; else rem2 += i ; } System . out . print ( maxRem0 + Math . max ( rem1 , rem2 ) ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 23 , 12 , 43 , 3 , 56 } ; getMax ( arr ) ; } }

Accumulator variables: ans, rem1, rem2
Iterator variables: ch, i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class pair { int first , second ; pair ( int a , int b ) { first = a ; second = b ; } } static int dfs ( Vector < Vector < pair > > g , pair disRev [ ] , boolean visit [ ] , int u ) { visit [ u ] = true ; int totalRev = 0 ; for ( int i = 0 ; i < g . get ( u ) . size ( ) ; i ++ ) { int v = g . get ( u ) . get ( i ) . first ; if ( ! visit [ v ] ) { disRev [ v ] . first = disRev [ u ] . first + 1 ; disRev [ v ] . second = disRev [ u ] . second ; if ( g . get ( u ) . get ( i ) . second != 0 ) { disRev [ v ] . second = disRev [ u ] . second + 1 ; totalRev ++ ; } totalRev += dfs ( g , disRev , visit , v ) ; } } return totalRev ; } static void printMinEdgeReverseForRootNode ( int edges [ ] [ ] , int e ) { int V = e + 1 ; Vector < Vector < pair > > g = new Vector < Vector < pair > > ( ) ; for ( int i = 0 ; i < V + 1 ; i ++ ) g . add ( new Vector < pair > ( ) ) ; pair disRev [ ] = new pair [ V ] ; for ( int i = 0 ; i < V ; i ++ ) disRev [ i ] = new pair ( 0 , 0 ) ; boolean visit [ ] = new boolean [ V ] ; int u , v ; for ( int i = 0 ; i < e ; i ++ ) { u = edges [ i ] [ 0 ] ; v = edges [ i ] [ 1 ] ; g . get ( u ) . add ( new pair ( v , 0 ) ) ; g . get ( v ) . add ( new pair ( u , 1 ) ) ; } for ( int i = 0 ; i < V ; i ++ ) { visit [ i ] = false ; disRev [ i ] . first = disRev [ i ] . second = 0 ; } int root = 0 ; int totalRev = dfs ( g , disRev , visit , root ) ; int res = Integer . MAX_VALUE ; for ( int i = 0 ; i < V ; i ++ ) { int edgesToRev = ( totalRev - disRev [ i ] . second ) + ( disRev [ i ] . first - disRev [ i ] . second ) ; if ( edgesToRev < res ) { res = edgesToRev ; root = i ; } } System . out . println ( root + " ▁ " + res ) ; } public static void main ( String args [ ] ) { int edges [ ] [ ] = { { 0 , 1 } , { 2 , 1 } , { 3 , 2 } , { 3 , 4 } , { 5 , 4 } , { 5 , 6 } , { 7 , 6 } } ; int e = edges . length ; printMinEdgeReverseForRootNode ( edges , e ) ; } }

Index/key variables: V, i, u, v
Accumulator variables: i, totalRev
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . io . * ; import java . util . * ; class GFG { static void checkString ( String s , int k ) { int n = s . length ( ) ; if ( 2 * k + 1 > n ) { System . out . println ( " No " ) ; return ; } String a = s . substring ( 0 , k ) ; String b = s . substring ( n - k , n ) ; StringBuffer str = new StringBuffer ( b ) ; str . reverse ( ) ; b = str . toString ( ) ; if ( a . equals ( b ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String S = " qwqwq " ; int K = 1 ; checkString ( S , K ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int findMin ( int [ ] arr , int N , int k ) { int pairs = 0 ; for ( int i = 0 ; i < N ; i ++ ) { pairs += arr [ i ] / 2 ; } if ( k > pairs ) return - 1 ; else return 2 * k + N - 1 ; } public static void main ( String [ ] args ) { int [ ] arr = { 4 , 5 , 6 } ; int K = 3 ; int N = arr . length ; System . out . println ( findMin ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: i, pairs
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int minimumFlips ( int A , int B , int C ) { int res = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) { int x = 0 , y = 0 , z = 0 ; if ( ( A & ( 1 << i ) ) != 0 ) { x = 1 ; } if ( ( B & ( 1 << i ) ) != 0 ) { y = 1 ; } if ( ( C & ( 1 << i ) ) != 0 ) { z = 1 ; } if ( z == 0 ) { if ( x == 1 ) { res ++ ; } if ( y == 1 ) { res ++ ; } } if ( z == 1 ) { if ( x == 0 && y == 0 ) { res ++ ; } } } return res ; } public static void main ( String [ ] args ) { int A = 2 , B = 6 , C = 5 ; System . out . println ( minimumFlips ( A , B , C ) ) ; } }

Accumulator variables: i, res
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int prefixCount [ ] [ ] ; static void findPrefixCount ( int arr [ ] , int size ) { for ( int i = 0 ; i < 32 ; i ++ ) { prefixCount [ i ] [ 0 ] = ( ( arr [ 0 ] >> i ) & 1 ) ; for ( int j = 1 ; j < size ; j ++ ) { prefixCount [ i ] [ j ] = ( ( arr [ j ] >> i ) & 1 ) ; prefixCount [ i ] [ j ] += prefixCount [ i ] [ j - 1 ] ; } } } static void arrayBitwiseAND ( int size ) { int result = 0 ; for ( int i = 0 ; i < 32 ; i ++ ) { int temp = prefixCount [ i ] [ size - 1 ] ; if ( temp == size ) result = ( result | ( 1 << i ) ) ; } System . out . print ( result + " ▁ " ) ; } static void applyQuery ( int currentVal , int newVal , int size ) { for ( int i = 0 ; i < 32 ; i ++ ) { int bit1 = ( ( currentVal >> i ) & 1 ) ; int bit2 = ( ( newVal >> i ) & 1 ) ; if ( bit2 > 0 && bit1 == 0 ) prefixCount [ i ] [ size - 1 ] ++ ; else if ( bit1 > 0 && bit2 == 0 ) prefixCount [ i ] [ size - 1 ] -- ; } } static void findbitwiseAND ( int queries [ ] [ ] , int arr [ ] , int N , int M ) { prefixCount = new int [ 32 ] [ 10000 ] ; findPrefixCount ( arr , N ) ; for ( int i = 0 ; i < M ; i ++ ) { int id = queries [ i ] [ 0 ] ; int newVal = queries [ i ] [ 1 ] ; int currentVal = arr [ id ] ; arr [ id ] = newVal ; applyQuery ( currentVal , newVal , N ) ; arrayBitwiseAND ( N ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int queries [ ] [ ] = { { 0 , 2 } , { 3 , 3 } , { 4 , 2 } } ; int N = arr . length ; int M = queries . length ; findbitwiseAND ( queries , arr , N , M ) ; } }

Index/key variables: i, id, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void stepscount ( int a , int b ) { int chanceA = 2 * a - 1 ; int chanceB = 2 * b ; if ( chanceA < chanceB ) { System . out . print ( " B " ) ; } else if ( chanceB < chanceA ) { System . out . print ( " A " ) ; } } public static void main ( String [ ] args ) { int A = 2 ; int B = 3 ; stepscount ( A , B ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void checkpoint ( int h , int k , int x , int y , int a , int b ) { int p = ( int ) ( Math . pow ( ( x - h ) , 2 ) / Math . pow ( a , 2 ) ) - ( int ) ( Math . pow ( ( y - k ) , 2 ) / Math . pow ( b , 2 ) ) ; if ( p > 1 ) { System . out . println ( " Outside " ) ; } else if ( p == 1 ) { System . out . println ( " On ▁ the ▁ Hyperbola " ) ; } else { System . out . println ( " Inside " ) ; } } public static void main ( String [ ] args ) { int h = 0 , k = 0 , x = 2 ; int y = 1 , a = 4 , b = 5 ; checkpoint ( h , k , x , y , a , b ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void evenXorSubarray ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int XOR = 0 ; for ( int j = i ; j < n ; j ++ ) { XOR = XOR ^ arr [ j ] ; if ( ( XOR & 1 ) == 0 ) ans ++ ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = arr . length ; evenXorSubarray ( arr , N ) ; } }

Index/key variables: j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void findKthElement ( int N , int K ) { int ans = 0 ; if ( K <= N / 2 ) { ans = K * 2 ; } else { if ( N % 2 == 0 ) { ans = ( K * 2 ) - N - 1 ; } else { ans = ( K * 2 ) - N ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int N = 10 , K = 3 ; findKthElement ( N , K ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int makeSumEqual ( int [ ] a , int [ ] b , int K , int M , int N ) { int sum1 = 0 ; int sum2 = 0 ; for ( int el : a ) sum1 += el ; for ( int el : b ) sum2 += el ; int diff = sum1 - sum2 ; int l1 = 0 , r1 = M - 1 ; int l2 = 0 , r2 = N - 1 ; int res = 0 ; Arrays . sort ( a ) ; Arrays . sort ( b ) ; while ( l1 <= r1 l2 <= r2 ) { if ( diff == 0 ) { break ; } if ( diff > 0 ) { if ( l2 <= r2 && l1 <= r1 ) { if ( K - b [ l2 ] < a [ r1 ] - 1 ) { int sub = Math . min ( a [ r1 ] - 1 , diff ) ; diff -= sub ; a [ r1 ] -= sub ; r1 -- ; } else { int sub = Math . min ( K - b [ l2 ] , diff ) ; diff -= sub ; b [ l2 ] += sub ; l2 ++ ; } } else if ( l1 <= r1 ) { int sub = Math . min ( a [ r1 ] - 1 , diff ) ; diff -= sub ; a [ r1 ] -= sub ; r1 -- ; } else { int sub = Math . min ( K - b [ l2 ] , diff ) ; diff -= sub ; b [ l2 ] += sub ; l2 ++ ; } } else { if ( l1 <= r1 && l2 <= r2 ) { if ( K - a [ l1 ] < b [ r2 ] - 1 ) { int sub = Math . min ( b [ r2 ] - 1 , - 1 * diff ) ; diff += sub ; b [ r2 ] -= sub ; r2 -- ; } else { int sub = Math . min ( K - a [ l1 ] , - 1 * diff ) ; diff += sub ; a [ l1 ] -= sub ; l1 ++ ; } } else if ( l2 <= r2 ) { int sub = Math . min ( b [ r2 ] - 1 , - 1 * diff ) ; diff += sub ; b [ r2 ] -= sub ; r2 -- ; } else { int sub = Math . min ( K - a [ l1 ] , diff ) ; diff += sub ; a [ l1 ] += sub ; l1 ++ ; } } res ++ ; } if ( diff == 0 ) return res ; else return - 1 ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 4 , 3 } ; int [ ] B = { 6 , 6 , 6 } ; int M = A . length ; int N = B . length ; int K = 6 ; System . out . println ( makeSumEqual ( A , B , K , M , N ) ) ; } }

Index/key variables: l1, l2, r1, r2
Accumulator variables: diff, l1, l2, r1, r2, res, sum1, sum2
Iterator variables: el
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static void findString ( char S [ ] , int N ) { int strLen = 4 * N ; for ( int i = 1 ; i <= N ; i ++ ) { S [ strLen - 1 ] = '1' ; strLen -= 2 ; } System . out . println ( S ) ; } public static void main ( String [ ] args ) { int N = 2 ; char S [ ] = new char [ 4 * N ] ; for ( int i = 0 ; i < 4 * N ; i ++ ) S [ i ] = '0' ; findString ( S , N ) ; } }

Index/key variables: i
Accumulator variables: i, strLen
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static boolean isVowel ( char ch ) { if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) return true ; if ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) return true ; return false ; } public static String containsEqualStrings ( String S ) { int totalVowels = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( isVowel ( S . charAt ( i ) ) ) totalVowels ++ ; } int vowelsTillNow = 0 ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) { if ( isVowel ( S . charAt ( i ) ) ) { vowelsTillNow ++ ; totalVowels -- ; if ( vowelsTillNow == totalVowels ) { return " Yes " ; } } } return " No " ; } public static void main ( String [ ] args ) { String S = " geeks " ; System . out . println ( containsEqualStrings ( S ) ) ; } }

Accumulator variables: i, totalVowels, vowelsTillNow
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void getMaxSum ( int [ ] [ ] A , int M , int N ) { int sum = 0 ; int negative = 0 ; int minVal = Integer . MAX_VALUE ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { sum += Math . abs ( A [ i ] [ j ] ) ; if ( A [ i ] [ j ] < 0 ) { negative ++ ; } minVal = Math . min ( minVal , Math . abs ( A [ i ] [ j ] ) ) ; } } if ( negative % 2 != 0 ) { sum -= 2 * minVal ; } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { int [ ] [ ] A = { { 4 , - 8 , 6 } , { 3 , 7 , 2 } } ; int M = A . length ; int N = A [ 0 ] . length ; getMaxSum ( A , M , N ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, negative, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void areaToPaint ( int N , int W , int L , int Heights [ ] ) { int total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { total += 2 * Heights [ i ] * W ; } total += L * ( Heights [ 0 ] + Heights [ N - 1 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { total += L * Math . abs ( Heights [ i ] - Heights [ i - 1 ] ) ; } System . out . print ( total ) ; } public static void main ( String [ ] args ) { int N = 7 , W = 1 , L = 1 ; int Heights [ ] = { 4 , 3 , 1 , 2 , 3 , 4 , 2 } ; areaToPaint ( N , W , L , Heights ) ; } }

Index/key variables: i
Accumulator variables: i, total
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int [ ] [ ] restoreGem ( int [ ] r , int [ ] c ) { int [ ] [ ] dp = new int [ r . length ] [ c . length ] ; for ( int i = 0 ; i < r . length ; i ++ ) { for ( int j = 0 ; j < c . length ; j ++ ) { int m = Math . min ( r [ i ] , c [ j ] ) ; dp [ i ] [ j ] = m ; r [ i ] -= m ; c [ j ] -= m ; } } return dp ; } static void printMatrix ( int [ ] [ ] ans , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { System . out . print ( ans [ i ] [ j ] + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int [ ] rowSum = { 5 , 7 , 10 } ; int [ ] colSum = { 8 , 6 , 8 } ; int [ ] [ ] ans = restoreGem ( rowSum , colSum ) ; printMatrix ( ans , rowSum . length , colSum . length ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int MAX = 1000000 ; static void maxSumOfDistinctPrimeFactors ( int [ ] arr , int N , int K ) { int [ ] CountDistinct = new int [ MAX + 1 ] ; boolean [ ] prime = new boolean [ MAX + 1 ] ; for ( int i = 0 ; i <= MAX ; i ++ ) { CountDistinct [ i ] = 0 ; prime [ i ] = true ; } for ( int i = 2 ; i <= MAX ; i ++ ) { if ( prime [ i ] == true ) { CountDistinct [ i ] = 1 ; for ( int j = i * 2 ; j <= MAX ; j += i ) { CountDistinct [ j ] ++ ; prime [ j ] = false ; } } } int sum = 0 ; int [ ] PrimeFactor = new int [ 20 ] ; for ( int i = 0 ; i < N ; i ++ ) { PrimeFactor [ CountDistinct [ arr [ i ] ] ] ++ ; } for ( int i = 19 ; i >= 1 ; i -- ) { while ( PrimeFactor [ i ] > 0 ) { sum += i ; PrimeFactor [ i ] -- ; K -- ; if ( K == 0 ) break ; } if ( K == 0 ) break ; } System . out . print ( sum ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 6 , 9 , 12 } ; int N = arr . length ; int K = 2 ; maxSumOfDistinctPrimeFactors ( arr , N , K ) ; } }

Index/key variables: i, j
Accumulator variables: K, i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxChange ( char [ ] str ) { if ( str . length <= 1 ) { return 0 ; } int minChanges = 0 ; for ( int i = 0 ; i < str . length - 1 ; i ++ ) { if ( str [ i ] == str [ i + 1 ] ) { str [ i + 1 ] = ' N ' ; minChanges += 1 ; } else if ( i > 0 && str [ i - 1 ] == str [ i + 1 ] ) { str [ i + 1 ] = ' N ' ; minChanges += 1 ; } } return minChanges ; } public static void main ( String [ ] args ) { String str = " bbbbbbb " ; System . out . print ( maxChange ( str . toCharArray ( ) ) ) ; } }

Index/key variables: i
Accumulator variables: i, minChanges
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void findMinKToMakeAllEqual ( int N , int A [ ] ) { Set < Integer > B = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { B . add ( A [ i ] ) ; } ArrayList < Integer > b = new ArrayList < Integer > ( B ) ; int M = b . size ( ) ; int i = 0 ; if ( M > 3 ) { System . out . print ( " - 1" ) ; } else if ( M == 3 ) { int B_1 = b . get ( i ++ ) ; int B_2 = b . get ( i ++ ) ; int B_3 = b . get ( i ++ ) ; if ( B_2 - B_1 == B_3 - B_2 ) { System . out . print ( B_2 - B_1 ) ; } else { System . out . print ( " - 1" ) ; } } else if ( M == 2 ) { int B_1 = b . get ( i ++ ) ; int B_2 = b . get ( i ++ ) ; if ( ( B_2 - B_1 ) % 2 == 0 ) { System . out . print ( ( B_2 - B_1 ) / 2 ) ; } else { System . out . print ( B_2 - B_1 ) ; } } else { System . out . print ( 0 ) ; } } public static void main ( String [ ] args ) { int A [ ] = { 1 , 3 , 5 , 1 } ; int N = A . length ; findMinKToMakeAllEqual ( N , A ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void computeLPSArray ( String pat , int M , int [ ] lps ) { int len = 0 ; lps [ 0 ] = 0 ; int i = 1 ; while ( i < M ) { if ( pat . charAt ( i ) == pat . charAt ( len ) ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } } static int KMPSearch ( String pat , String txt ) { int M = pat . length ( ) ; int N = txt . length ( ) ; int lps [ ] = new int [ M ] ; computeLPSArray ( pat , M , lps ) ; int i = 0 ; int j = 0 ; while ( i < N ) { if ( pat . charAt ( j ) == txt . charAt ( i ) ) { j ++ ; i ++ ; } if ( j == M ) { return 1 ; else if ( i < N && pat . charAt ( j ) != txt . charAt ( i ) ) { if ( j != 0 ) j = lps [ j - 1 ] ; else i = i + 1 ; } } return 0 ; } static void maxRepeating ( String seq , String word ) { int resCount = 0 ; String curWord = word ; int numWords = seq . length ( ) / word . length ( ) ; for ( int i = 0 ; i < numWords ; i ++ ) { if ( KMPSearch ( curWord , seq ) == 1 ) { curWord += word ; resCount ++ ; } else break ; } System . out . print ( resCount ) ; } public static void main ( String [ ] args ) { String S1 = " ababc " , S2 = " ab " ; maxRepeating ( S1 , S2 ) ; } }

Index/key variables: M, i
Accumulator variables: curWord, i, j, len, resCount
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static long countNumberOfStrings ( String s ) { int n = s . length ( ) - 1 ; long count = ( long ) ( Math . pow ( 2 , n ) ) ; return count ; } public static void main ( String [ ] args ) { String S = " ABCD " ; System . out . println ( countNumberOfStrings ( S ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { static void findMinimumTime ( int [ ] p , int n , int target ) { HashMap < Integer , Integer > um = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! um . containsKey ( p [ i ] ) ) um . put ( p [ i ] , 1 ) ; else um . put ( p [ i ] , um . get ( p [ i ] ) + 1 ) ; } int time = 0 ; int sum = 0 ; while ( sum < target ) { sum = 0 ; time ++ ; for ( Map . Entry < Integer , Integer > it : um . entrySet ( ) ) { sum += it . getValue ( ) * ( time / it . getKey ( ) ) ; } } System . out . println ( time ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 1 , 3 , 3 , 4 } ; int N = arr . length ; int target = 10 ; findMinimumTime ( arr , N , target ) ; } }

Index/key variables: i
Accumulator variables: i, sum, time
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAXN = 100001 ; static void constructMEX ( int arr [ ] , int N ) { int hash [ ] = new int [ MAXN ] ; for ( int i = 0 ; i < N ; i ++ ) { hash [ i ] = 0 ; } for ( int i = 0 ; i < N ; i ++ ) { hash [ arr [ i ] ] = 1 ; } int MexOfArr = 0 ; for ( int i = 1 ; i < MAXN ; i ++ ) { if ( hash [ i ] == 0 ) { MexOfArr = i ; break ; } } int B [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < MexOfArr ) B [ i ] = arr [ i ] ; else B [ i ] = MexOfArr ; } for ( int i = 0 ; i < N ; i ++ ) System . out . print ( B [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 1 , 5 , 3 } ; int N = arr . length ; constructMEX ( arr , N ) ; } }

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