dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; class GFG { public static void minimumMoves ( int [ ] arr , int N ) { int sum = 0 ; int maxelement = - 1 ; if ( N == 2 ) { System . out . print ( "0" ) ; return ; } for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; maxelement = Math . max ( maxelement , arr [ i ] ) ; } int k = ( sum + N - 2 ) / ( N - 1 ) ; k = Math . max ( maxelement , k ) ; int ans = k * ( N - 1 ) - sum ; System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 7 } ; int N = arr . length ; minimumMoves ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static void printSubsequence ( int N ) { System . out . print ( " { ▁ " ) ; for ( int i = 1 ; i < N - 1 ; i ++ ) { System . out . print ( i + " , ▁ " ) ; } System . out . println ( N - 1 + " ▁ } " ) ; System . out . print ( " { ▁ " + N + " ▁ } " ) ; } public static void main ( String [ ] args ) { int N = 8 ; printSubsequence ( N ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static void array_divisbleby_k ( int N , int K ) { boolean flag = false ; int d1 = 0 , d2 = 0 ; for ( int i = 2 ; i * i <= K ; i ++ ) { if ( K % i == 0 ) { flag = true ; d1 = i ; d2 = K / i ; break ; } } if ( flag ) { for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 1 ) { System . out . print ( d2 + " ▁ " ) ; } else { System . out . print ( d1 + " ▁ " ) ; } } } else { System . out . print ( - 1 ) ; } } public static void main ( String [ ] args ) { int N = 5 , K = 21 ; array_divisbleby_k ( N , K ) ; } }

Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void addEdge ( Vector < Integer > adj [ ] , int u , int v ) { adj [ u ] . add ( v ) ; adj [ v ] . add ( u ) ; } static int cnt = 0 ; static boolean [ ] visited ; static void DFS ( int u , Vector < Integer > adj [ ] , int fre [ ] , String S ) { visited [ u ] = true ; cnt ++ ; fre [ S . charAt ( u ) - ' a ' ] ++ ; for ( int i = 0 ; i < adj [ u ] . size ( ) ; i ++ ) { if ( ! visited [ adj [ u ] . get ( i ) ] ) { DFS ( adj [ u ] . get ( i ) , adj , fre , S ) ; } } } static void minimumOperations ( String S , int m ) { int V = 100 ; @ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] adj = new Vector [ V ] ; int total = 0 , N = S . length ( ) ; for ( int i = 0 ; i < adj . length ; i ++ ) adj [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { addEdge ( adj , i , N - i - 1 ) ; addEdge ( adj , N - i - 1 , i ) ; } for ( int i = 0 ; i < N - m ; i ++ ) { addEdge ( adj , i , i + m ) ; addEdge ( adj , i + m , i ) ; } visited = new boolean [ V ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! visited [ i ] ) { int fre [ ] = new int [ 26 ] ; cnt = 0 ; int maxx = - 1 ; DFS ( i , adj , fre , S ) ; for ( int j = 0 ; j < 26 ; j ++ ) maxx = Math . max ( maxx , fre [ j ] ) ; total += cnt - maxx ; } } System . out . print ( total ) ; } public static void main ( String [ ] args ) { String S = " abaaba " ; int K = 2 ; minimumOperations ( S , K ) ; } }

Index/key variables: V, i, j, u, v
Accumulator variables: cnt, i, j, total
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static void print ( char arr [ ] [ ] , int n , int m ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { char a = arr [ i ] [ j ] ; if ( ( i + j ) % 2 == 0 && a == ' F ' ) { arr [ i ] [ j ] = '1' ; } else if ( a == ' F ' ) { arr [ i ] [ j ] = '2' ; } } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { System . out . print ( arr [ i ] [ j ] ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int n = 4 , m = 4 ; char arr [ ] [ ] = { { ' F ' , ' F ' , ' F ' , ' F ' } , { ' F ' , ' O ' , ' F ' , ' F ' } , { ' F ' , ' F ' , ' O ' , ' F ' } , { ' F ' , ' F ' , ' F ' , ' F ' } } ; print ( arr , n , m ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static String removeDuplicateLetters ( String s ) { int [ ] cnt = new int [ 26 ] ; int [ ] vis = new int [ 26 ] ; int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) cnt [ s . charAt ( i ) - ' a ' ] ++ ; String res = " " ; for ( int i = 0 ; i < n ; i ++ ) { cnt [ s . charAt ( i ) - ' a ' ] -- ; if ( vis [ s . charAt ( i ) - ' a ' ] == 0 ) { int size = res . length ( ) ; while ( size > 0 && res . charAt ( size - 1 ) > s . charAt ( i ) && cnt [ res . charAt ( size - 1 ) - ' a ' ] > 0 ) { vis [ res . charAt ( size - 1 ) - ' a ' ] = 0 ; res = res . substring ( 0 , size - 1 ) ; size -- ; } res += s . charAt ( i ) ; vis [ s . charAt ( i ) - ' a ' ] = 1 ; } } return res ; } public static void main ( String [ ] args ) { String S = " acbc " ; System . out . println ( removeDuplicateLetters ( S ) ) ; } }

Accumulator variables: i, res, size
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void countPairs ( int arr [ ] , int N ) { int countPowerof2 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( Integer . bitCount ( arr [ i ] ) == 1 ) countPowerof2 ++ ; } int desiredPairs = ( countPowerof2 * ( countPowerof2 - 1 ) ) / 2 ; System . out . print ( desiredPairs + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 7 , 2 } ; int N = arr . length ; countPairs ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: countPowerof2, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int MAXN = 1000000 ; static int is_prime [ ] ; static int count_of_primes [ ] ; static void sieve ( ) { is_prime = new int [ MAXN ] ; count_of_primes = new int [ MAXN ] ; Arrays . fill ( is_prime , 0 ) ; Arrays . fill ( count_of_primes , 0 ) ; for ( int i = 3 ; i < MAXN ; i += 2 ) { is_prime [ i ] = 1 ; } for ( int i = 3 ; i * i < MAXN ; i += 2 ) { if ( is_prime [ i ] == 1 ) { for ( int j = i * i ; j < MAXN ; j += i ) { is_prime [ j ] = 0 ; } } } is_prime [ 2 ] = 1 ; for ( int i = 1 ; i < MAXN ; i ++ ) count_of_primes [ i ] = count_of_primes [ i - 1 ] + is_prime [ i ] ; } static long power ( long x , long y , long p ) { long result = 1 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) result = ( result * x ) % p ; x = ( x * x ) % p ; y >>= 1 ; } return result ; } static void numberOfWays ( int N ) { long count = count_of_primes [ N ] - 1 ; long mod = 1000000007 ; long answer = power ( 2 , count , mod ) ; if ( N == 1 ) answer = 0 ; long ans = answer ; System . out . println ( ans ) ; } public static void main ( String [ ] args ) { sieve ( ) ; int N = 7 ; numberOfWays ( N ) ; } }

Index/key variables: MAXN, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static void maxSumOfSquares ( int N , int S ) { int res = 0 ; if ( S < N S > 9 * N ) { System . out . println ( - 1 ) ; return ; } S = S - N ; int c = 0 ; while ( S > 0 ) { c ++ ; if ( S / 8 > 0 ) { res += 9 * 9 ; S -= 8 ; } else { res += ( S + 1 ) * ( S + 1 ) ; break ; } } res = res + ( N - c ) ; System . out . println ( res ) ; } public static void main ( String args [ ] ) { int N = 3 ; int S = 12 ; maxSumOfSquares ( N , S ) ; } }

Accumulator variables: S, c, res
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int clearLastBit ( int N , int K ) { int mask = ( - 1 << K + 1 ) ; return N = N & mask ; } public static void main ( String [ ] args ) { int N = 730 , K = 3 ; System . out . print ( clearLastBit ( N , K ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isPossible ( int r , int b , int g ) { r = r % 3 ; b = b % 3 ; g = g % 3 ; if ( r == b b == g g == r ) { return true ; } else { return false ; } } public static void main ( String [ ] args ) { int R = 1 , B = 3 , G = 6 ; if ( isPossible ( R , B , G ) ) { System . out . print ( " Yes " + "NEW_LINE"); } else { System . out . print ( " No " + "NEW_LINE"); } } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int calculate_steps ( Integer arr [ ] , int n , int minimum ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int val = arr [ i ] ; if ( arr [ i ] > minimum ) { arr [ i ] = arr [ i ] - minimum ; count += arr [ i ] / 5 ; arr [ i ] = arr [ i ] % 5 ; count += arr [ i ] / 2 ; arr [ i ] = arr [ i ] % 2 ; if ( arr [ i ] > 0 ) { count ++ ; } } arr [ i ] = val ; } return count ; } static int solve ( Integer arr [ ] , int n ) { Arrays . sort ( arr , Collections . reverseOrder ( ) ) ; int minimum = arr [ n - 1 ] ; int count1 = 0 , count2 = 0 , count3 = 0 ; count1 = calculate_steps ( arr , n , minimum ) ; count2 = calculate_steps ( arr , n , minimum - 1 ) ; count3 = calculate_steps ( arr , n , minimum - 2 ) ; return Math . min ( count1 , Math . min ( count2 , count3 ) ) ; } public static void main ( String [ ] args ) { Integer arr [ ] = { 3 , 6 , 6 } ; int N = arr . length ; System . out . print ( solve ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static String mergePalindromes ( StringBuilder S , StringBuilder P ) { Map < Character , Integer > mapS = new HashMap < > ( ) , mapP = new HashMap < > ( ) , mapT = new HashMap < > ( ) ; int n = S . length ( ) , m = P . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mapS . put ( S . charAt ( i ) , mapS . getOrDefault ( S . charAt ( i ) , 0 ) + 1 ) ; } for ( int i = 0 ; i < m ; i ++ ) { mapP . put ( P . charAt ( i ) , mapP . getOrDefault ( P . charAt ( i ) , 0 ) + 1 ) ; } for ( char i = ' a ' ; i <= ' z ' ; i ++ ) { if ( mapS . getOrDefault ( i , 0 ) % 2 == 0 ) { mapT . put ( i , mapT . getOrDefault ( i , 0 ) + mapS . getOrDefault ( i , 0 ) ) ; mapS . put ( i , 0 ) ; } else { mapT . put ( i , mapT . getOrDefault ( i , 0 ) + mapS . getOrDefault ( i , 0 ) - 1 ) ; mapS . put ( i , 1 ) ; } if ( mapP . getOrDefault ( i , 0 ) % 2 == 0 ) { mapT . put ( i , mapT . getOrDefault ( i , 0 ) + mapP . getOrDefault ( i , 0 ) ) ; mapP . put ( i , 0 ) ; } else { mapT . put ( i , mapT . getOrDefault ( i , 0 ) + mapP . getOrDefault ( i , 0 ) - 1 ) ; mapP . put ( i , 1 ) ; } } int check = 0 ; for ( char i = ' a ' ; i <= ' z ' ; i ++ ) { if ( mapS . getOrDefault ( i , 0 ) > 0 && mapP . getOrDefault ( i , 0 ) > 0 ) { mapT . put ( i , mapT . getOrDefault ( i , 0 ) + 2 ) ; check = 1 ; break ; } } StringBuilder half1 = new StringBuilder ( ) , half2 = new StringBuilder ( ) ; for ( char i = ' a ' ; i <= ' z ' ; i ++ ) { for ( int j = 0 ; ( 2 * j ) < mapT . getOrDefault ( i , 0 ) ; j ++ ) { half1 . append ( i ) ; half2 . append ( i ) ; } } StringBuilder tmp = half2 . reverse ( ) ; if ( check == 1 ) { return half1 . append ( tmp ) . toString ( ) ; } for ( char i = ' a ' ; i <= ' z ' ; i ++ ) { if ( mapS . getOrDefault ( i , 0 ) > 0 || mapP . getOrDefault ( i , 0 ) > 0 ) { half1 . append ( i ) ; return half1 . append ( tmp ) . toString ( ) ; } } return half1 . append ( tmp ) . toString ( ) ; } public static void main ( String [ ] args ) { StringBuilder S = new StringBuilder ( " aeabb " ) ; StringBuilder P = new StringBuilder ( " dfedf " ) ; System . out . println ( mergePalindromes ( S , P ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countOfSubarray ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) arr [ i ] -- ; int [ ] pref = new int [ N ] ; pref [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) pref [ i ] = pref [ i - 1 ] + arr [ i ] ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; int answer = 0 ; mp . put ( 0 , 1 ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . containsKey ( pref [ i ] ) ) { answer += mp . get ( pref [ i ] ) ; mp . put ( pref [ i ] , mp . get ( pref [ i ] ) + 1 ) ; } else { mp . put ( pref [ i ] , 1 ) ; } } return answer ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 0 } ; int N = arr . length ; System . out . print ( countOfSubarray ( arr , N ) ) ; } }

Index/key variables: N, i
Accumulator variables: answer, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void printsubset ( int n , int k ) { int count = 0 , x = 0 ; ArrayList < Integer > vec = new ArrayList < > ( ) ; while ( n != 0 ) { x = n & 1 ; if ( x != 0 ) { vec . add ( ( int ) Math . pow ( k , count ) ) ; } n = n >> 1 ; count ++ ; } for ( int i = 0 ; i < vec . size ( ) ; i ++ ) System . out . print ( vec . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 7 , k = 4 ; printsubset ( n , k ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int solve ( String s , int x , int y ) { int res = 0 ; for ( char c : s . toCharArray ( ) ) { if ( c - '0' == x ) { res ++ ; x = x + y ; y = x - y ; x = x - y ; } } if ( x != y && res % 2 == 1 ) -- res ; return res ; } static int find_min ( String s ) { int count = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { count = Math . max ( count , solve ( s , i , j ) ) ; } } return count ; } public static void main ( String [ ] args ) { String s = "100120013" ; int n = s . length ( ) ; int answer = find_min ( s ) ; System . out . print ( ( n - answer ) ) ; } }

Accumulator variables: i, j, res
Iterator variables: c, i, j
Class/struct names: GFG
Java program:
class GFG { static int countSetBitsUtil ( int x ) { if ( x <= 0 ) return 0 ; return ( ( x % 2 == 0 ? 0 : 1 ) + countSetBitsUtil ( x / 2 ) ) ; } static int countSetBits ( int L , int R ) { int bitCount = 0 ; for ( int i = L ; i <= R ; i ++ ) { bitCount += countSetBitsUtil ( i ) ; } return bitCount ; } public static void main ( String [ ] args ) { int L = 3 , R = 5 ; System . out . printf ( " Total ▁ set ▁ bit ▁ count ▁ is ▁ % d " , countSetBits ( L , R ) ) ; } }

Accumulator variables: bitCount, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void values_of_Q ( int X ) { ArrayList < Integer > val_Q = new ArrayList < Integer > ( ) ; for ( int i = 1 ; i <= X ; i ++ ) { if ( ( ( ( X + i ) * X ) ) % i == 0 ) { val_Q . add ( X + i ) ; } } System . out . println ( val_Q . size ( ) ) ; for ( int i = 0 ; i < val_Q . size ( ) ; i ++ ) { System . out . print ( val_Q . get ( i ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int X = 3 ; values_of_Q ( X ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GCD { static String gcd ( String str1 , String str2 ) { if ( str1 . length ( ) < str2 . length ( ) ) { return gcd ( str2 , str1 ) ; } else if ( ! str1 . startsWith ( str2 ) ) { return " " ; } else if ( str2 . isEmpty ( ) ) { return str1 ; } else { return gcd ( str1 . substring ( str2 . length ( ) ) , str2 ) ; } } static String findGCD ( String arr [ ] , int n ) { String result = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { result = gcd ( result , arr [ i ] ) ; } return result ; } public static void main ( String [ ] args ) { String arr [ ] = new String [ ] { " GFGGFG " , " GFGGFG " , " GFGGFGGFGGFG " } ; int n = arr . length ; System . out . println ( findGCD ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GCD
Java program:
import java . util . * ; class GFG { static final int N = 4 ; static final int M = 4 ; static String balancedMatrix ( int mat [ ] [ ] ) { boolean is_balanced = true ; for ( int i = 0 ; i < N && is_balanced ; i ++ ) { for ( int j = 0 ; j < M && is_balanced ; j ++ ) { if ( ( i == 0 i == N - 1 ) && ( j == 0 j == M - 1 ) ) { if ( mat [ i ] [ j ] >= 2 ) is_balanced = false ; } else if ( i == 0 i == N - 1 j == 0 j == M - 1 ) { if ( mat [ i ] [ j ] >= 3 ) is_balanced = false ; } else { if ( mat [ i ] [ j ] >= 4 ) is_balanced = false ; } } } if ( is_balanced ) return " Balanced " ; else return " Unbalanced " ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 1 , 2 , 3 , 4 } , { 3 , 5 , 2 , 6 } , { 5 , 3 , 6 , 1 } , { 9 , 5 , 6 , 0 } } ; System . out . print ( balancedMatrix ( mat ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: is_balanced
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String unixTimeToHumanReadable ( int seconds ) { String ans = " " ; int daysOfMonth [ ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; int currYear , daysTillNow , extraTime , extraDays , index , date , month , hours , minutes , secondss , flag = 0 ; daysTillNow = seconds / ( 24 * 60 * 60 ) ; extraTime = seconds % ( 24 * 60 * 60 ) ; currYear = 1970 ; while ( daysTillNow >= 365 ) { if ( currYear % 400 == 0 || ( currYear % 4 == 0 && currYear % 100 != 0 ) ) { daysTillNow -= 366 ; } else { daysTillNow -= 365 ; } currYear += 1 ; } extraDays = daysTillNow + 1 ; if ( currYear % 400 == 0 || ( currYear % 4 == 0 && currYear % 100 != 0 ) ) flag = 1 ; month = 0 ; index = 0 ; if ( flag == 1 ) { while ( true ) { if ( index == 1 ) { if ( extraDays - 29 < 0 ) break ; month += 1 ; extraDays -= 29 ; } else { if ( extraDays - daysOfMonth [ index ] < 0 ) { break ; } month += 1 ; extraDays -= daysOfMonth [ index ] ; } index += 1 ; } } else { while ( true ) { if ( extraDays - daysOfMonth [ index ] < 0 ) { break ; } month += 1 ; extraDays -= daysOfMonth [ index ] ; index += 1 ; } } if ( extraDays > 0 ) { month += 1 ; date = extraDays ; } else { if ( month == 2 && flag == 1 ) date = 29 ; else { date = daysOfMonth [ month - 1 ] ; } } hours = extraTime / 3600 ; minutes = ( extraTime % 3600 ) / 60 ; secondss = ( extraTime % 3600 ) % 60 ; ans += String . valueOf ( date ) ; ans += " / " ; ans += String . valueOf ( month ) ; ans += " / " ; ans += String . valueOf ( currYear ) ; ans += " ▁ " ; ans += String . valueOf ( hours ) ; ans += " : " ; ans += String . valueOf ( minutes ) ; ans += " : " ; ans += String . valueOf ( secondss ) ; return ans ; } public static void main ( String [ ] args ) { int T = 1595497956 ; String ans = unixTimeToHumanReadable ( T ) ; System . out . print ( ans + "NEW_LINE"); } }

Index/key variables: index
Accumulator variables: ans, currYear, daysTillNow, extraDays, index, month
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static double AreaofRectangle ( int L , int W ) { double area = ( W + L ) * ( W + L ) / 2 ; return area ; } public static void main ( String args [ ] ) { int L = 18 ; int W = 12 ; System . out . println ( AreaofRectangle ( L , W ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static int downToZero ( int n ) { if ( n <= 3 ) return n ; int [ ] dp = new int [ n + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) dp [ i ] = - 1 ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; dp [ 2 ] = 2 ; dp [ 3 ] = 3 ; int sqr ; for ( int i = 4 ; i <= n ; i ++ ) { sqr = ( int ) Math . sqrt ( i ) ; int best = Integer . MAX_VALUE ; while ( sqr > 1 ) { if ( i % sqr == 0 ) { best = Math . min ( best , 1 + dp [ sqr ] ) ; } sqr -- ; } best = Math . min ( best , 1 + dp [ i - 1 ] ) ; dp [ i ] = best ; } return dp [ n ] ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( downToZero ( n ) ) ; } }

Index/key variables: i, n, sqr
Accumulator variables: i, sqr
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int downToZero ( int n ) { if ( n <= 3 ) return n ; return n % 2 == 0 ? 3 : 4 ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . println ( downToZero ( n ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static int minimumrequired ( int A [ ] , int N ) { int K = N ; int ans = 0 ; while ( K > 0 ) { if ( K % 2 == 1 ) { ans = K ; break ; } int ispalindrome = 1 ; for ( int i = 0 ; i < K / 2 ; i ++ ) { if ( A [ i ] != A [ K - 1 - i ] ) ispalindrome = 0 ; } if ( ispalindrome == 1 ) { ans = K / 2 ; K /= 2 ; } else { ans = K ; break ; } } return ans ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 2 , 1 , 1 , 2 , 2 , 1 } ; int N = a . length ; System . out . println ( minimumrequired ( a , N ) ) ; } }

Index/key variables: i
Accumulator variables: K, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int sumOfFactors ( int N ) { int ans = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { int first = i ; int last = ( N / i ) * i ; int factors = ( last - first ) / i + 1 ; int totalContribution = ( ( ( factors ) * ( factors + 1 ) ) / 2 ) * i ; ans += totalContribution ; } return ans ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . println ( sumOfFactors ( N ) ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int getMaxDifference ( int N ) { int M = - 1 ; int maxDiff = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int diff = ( N ^ i ) - ( N & i ) ; if ( diff >= maxDiff ) { maxDiff = diff ; M = i ; } } return M ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . print ( getMaxDifference ( N ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int findM ( int N ) { int M = 0 ; int MSB = ( int ) Math . log ( N ) ; for ( int i = 0 ; i < MSB ; i ++ ) { if ( ( N & ( 1 << i ) ) == 0 ) M += ( 1 << i ) ; } return M ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . print ( findM ( N ) ) ; } }

Accumulator variables: M, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static double cont [ ] [ ] = new double [ 1000 ] [ 1000 ] ; static void num_of_containers ( int n , double x ) { int count = 0 ; cont [ 1 ] [ 1 ] = x ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { if ( cont [ i ] [ j ] >= ( double ) 1 ) { count ++ ; cont [ i + 1 ] [ j ] += ( cont [ i ] [ j ] - ( double ) 1 ) / ( double ) 2 ; cont [ i + 1 ] [ j + 1 ] += ( cont [ i ] [ j ] - ( double ) 1 ) / ( double ) 2 ; } } } System . out . print ( count ) ; } public static void main ( String [ ] args ) { int n = 3 ; double x = 5 ; num_of_containers ( n , x ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static boolean findTriplet ( int [ ] arr ) { int n = arr . length ; Stack < Integer > st = new Stack < > ( ) ; int h3 = Integer . MIN_VALUE ; int h1 = Integer . MAX_VALUE ; for ( int i = n - 1 ; i >= 0 ; i -- ) { h1 = arr [ i ] ; while ( ! st . empty ( ) && st . peek ( ) < arr [ i ] ) { h3 = st . peek ( ) ; st . pop ( ) ; } st . push ( arr [ i ] ) ; if ( h1 < h3 ) { return true ; } } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 7 , 5 , 6 } ; if ( findTriplet ( arr ) ) { 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:
import java . util . * ; class GFG { static int distinctNumbers ( int arr [ ] , int m , int n ) { Map < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) count . put ( arr [ i ] , count . getOrDefault ( arr [ i ] , 0 ) + 1 ) ; int [ ] fre_arr = new int [ n + 1 ] ; for ( Integer it : count . values ( ) ) { fre_arr [ it ] ++ ; } int ans = count . size ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { int temp = fre_arr [ i ] ; if ( temp == 0 ) continue ; int t = Math . min ( temp , m / i ) ; ans -= t ; m -= i * t ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 1 , 5 , 3 , 5 , 1 , 3 } ; int n = arr . length ; int m = 2 ; System . out . println ( distinctNumbers ( arr , m , n ) ) ; } }

Index/key variables: i, it
Accumulator variables: ans, i, m
Iterator variables: i, it
Class/struct names: GFG