dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void shortestSubarray ( int A [ ] , int N ) { int i ; int left_index ; for ( i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] + 1 != A [ i + 1 ] ) break ; } left_index = i ; int right_index ; for ( i = N - 1 ; i >= 1 ; i -- ) { if ( A [ i ] != A [ i - 1 ] + 1 ) break ; } right_index = i ; int updated_right ; int minLength = Math . min ( N - left_index - 1 , right_index ) ; if ( A [ right_index ] <= A [ left_index ] + 1 ) { updated_right = right_index + A [ left_index ] - A [ right_index ] + 1 ; if ( updated_right < N ) minLength = Math . min ( minLength , updated_right - left_index - 1 ) ; } System . out . println ( minLength ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 7 , 4 , 3 , 5 } ; int N = arr . length ; shortestSubarray ( arr , N ) ; } }

Index/key variables: i, left_index, right_index
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static String freqCheck ( String S , int N ) { int hash [ ] = new int [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { hash [ S . charAt ( i ) - ' a ' ] ++ ; } for ( int i = 0 ; i < 26 ; i ++ ) { if ( hash [ i ] > 2 ) { return " Yes " ; } } return " No " ; } public static void main ( String [ ] args ) { String S = " geekseekforgeeks " ; int N = S . length ( ) ; System . out . println ( freqCheck ( S , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . lang . * ; import java . util . * ; class GFG { static int minLength ( String s ) { int i = 0 , j = s . length ( ) - 1 ; for ( ; i < j && s . charAt ( i ) == s . charAt ( j ) ; ) { char d = s . charAt ( i ) ; while ( i <= j && s . charAt ( i ) == d ) i ++ ; while ( i <= j && s . charAt ( j ) == d ) j -- ; } return j - i + 1 ; } public static void main ( String [ ] args ) { String S = " aacbcca " ; System . out . println ( minLength ( S ) ) ; } }

Accumulator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int mod = 1000000007 ; static long power ( long x , int y ) { long res = 1 ; x = x % mod ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % mod ; y = y >> 1 ; x = ( x * x ) % mod ; } return res ; } static long CountBST ( int H ) { return power ( 2 , H ) ; } public static void main ( String [ ] args ) { int H = 2 ; System . out . print ( CountBST ( H ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static void rotateString ( int n , int m , String s ) { int v [ ] = new int [ n ] ; int cnt = 0 ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '1' ) { v [ j ] = i ; j += 1 ; } } for ( int i = 1 ; i < j ; i ++ ) { if ( ( v [ i ] - v [ i - 1 ] - 1 ) > m ) { cnt ++ ; } } if ( j >= 2 && ( n - ( v [ j - 1 ] - v [ 0 ] ) - 1 ) > m ) { cnt ++ ; } if ( cnt <= 1 ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } public static void main ( String [ ] args ) { String S = "101001" ; int M = 1 ; int N = S . length ( ) ; rotateString ( N , M , S ) ; } }

Index/key variables: i, j, n
Accumulator variables: cnt, i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findNumber ( int N ) { int [ ] ans = { 1 , 2 , 4 , 8 , 7 , 5 } ; return ans [ N % 6 ] ; } public static void main ( String args [ ] ) { int N = 6 ; System . out . println ( findNumber ( N ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void canBeEmptied ( int A , int B ) { if ( Math . max ( A , B ) > 2 * Math . min ( A , B ) ) { System . out . println ( " No " ) ; return ; } if ( ( A + B ) % 3 == 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int A = 1 , B = 2 ; canBeEmptied ( A , B ) ; } }

Class/struct names: GFG
Java program:
class GFG { static void maximumIndex ( int N , int B ) { int i = 0 , j = 1 ; int cnt = 0 ; int sum = N * ( N + 1 ) / 2 ; boolean flag = false ; while ( cnt < N ) { i += j ; j ++ ; cnt ++ ; if ( i == B ) { flag = true ; break ; } } if ( ! flag == true ) { System . out . print ( sum ) ; } else { System . out . print ( sum - 1 ) ; } } public static void main ( String [ ] args ) { int N = 4 , B = 6 ; maximumIndex ( N , B ) ; } }

Accumulator variables: cnt, i, j
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void findLongestArray ( int K ) { ArrayList < int [ ] > primefactors = new ArrayList < > ( ) ; int K_temp = K ; for ( int i = 2 ; i * i <= K ; i ++ ) { int count = 0 ; while ( K_temp % i == 0 ) { K_temp /= i ; count ++ ; } if ( count > 0 ) primefactors . add ( new int [ ] { count , i } ) ; } if ( K_temp != 1 ) primefactors . add ( new int [ ] { 1 , K_temp } ) ; Collections . sort ( primefactors , ( x , y ) -> { if ( x [ 0 ] != y [ 0 ] ) return y [ 0 ] - x [ 0 ] ; return y [ 1 ] - x [ 1 ] ; } ) ; int n = primefactors . get ( 0 ) [ 0 ] ; int val = primefactors . get ( 0 ) [ 1 ] ; int answer [ ] = new int [ n ] ; Arrays . fill ( answer , val ) ; answer [ n - 1 ] *= K ; for ( int i = 0 ; i < n ; i ++ ) { answer [ n - 1 ] /= val ; } System . out . print ( " { " ) ; for ( int i = 0 ; i < answer . length ; i ++ ) { if ( i == answer . length - 1 ) System . out . print ( answer [ i ] + " } " ) ; else System . out . print ( answer [ i ] + " , ▁ " ) ; } } public static void main ( String [ ] args ) { int K = 4 ; findLongestArray ( K ) ; } }

Index/key variables: i, n
Accumulator variables: K_temp, count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void minsteps ( int [ ] A ) { int n = A . length ; int [ ] left = new int [ n ] ; Arrays . fill ( left , 0 ) ; int [ ] right = new int [ n ] ; Arrays . fill ( right , 0 ) ; int [ ] res = new int [ n ] ; Arrays . fill ( res , 0 ) ; int count = A [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { left [ i ] = left [ i - 1 ] + count ; count += A [ i ] ; } count = A [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { right [ i ] = right [ i + 1 ] + count ; count += A [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { res [ i ] = left [ i ] + right [ i ] ; System . out . print ( res [ i ] + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 0 , 1 , 0 } ; minsteps ( A ) ; } }

Index/key variables: i, n
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void minimumOperations ( int [ ] A , int K ) { int [ ] isflipped = new int [ A . length + 1 ] ; int ans = 0 ; for ( int i = 0 ; i < A . length ; i ++ ) { if ( i > 0 ) { isflipped [ i ] += isflipped [ i - 1 ] ; isflipped [ i ] %= 2 ; } if ( A [ i ] == 0 && isflipped [ i ] == 0 ) { if ( ( A . length - i + 1 ) <= K ) { System . out . println ( - 1 ) ; return ; } ans ++ ; isflipped [ i ] ++ ; isflipped [ i + K ] -- ; } else if ( A [ i ] == 1 && isflipped [ i ] != 0 ) { if ( ( A . length - i + 1 ) <= K ) { System . out . println ( - 1 ) ; return ; } ans ++ ; isflipped [ i ] ++ ; isflipped [ i + K ] -- ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 0 , 1 , 0 } ; int K = 1 ; minimumOperations ( arr , K ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void findScoreSum ( int n ) { int total = 0 ; int prev_monday = 0 , curr_day = 0 ; for ( int day = 1 ; day <= n ; day ++ ) { if ( day % 7 == 1 ) { prev_monday ++ ; curr_day = prev_monday ; } total += curr_day ++ ; } System . out . println ( total ) ; } public static void main ( String [ ] args ) { int N = 8 ; findScoreSum ( N ) ; } }

Accumulator variables: curr_day, day, prev_monday, total
Iterator variables: day
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void findScoreSum ( int n ) { int F = n / 7 ; int D = n % 7 ; int fullWeekScore = ( 49 + 7 * F ) * F / 2 ; int lastNonFullWeekScore = ( 2 * F + D + 1 ) * D / 2 ; System . out . println ( fullWeekScore + lastNonFullWeekScore ) ; } public static void main ( String [ ] args ) { int N = 8 ; findScoreSum ( N ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static long maximumNum ( long X , long Y , long N ) { long num = 0 ; if ( N - N % X + Y <= N ) { num = N - N % X + Y ; } else { num = N - N % X - ( X - Y ) ; } return num ; } public static void main ( String [ ] args ) { long X = 10 ; long Y = 5 ; long N = 15 ; System . out . println ( maximumNum ( X , Y , N ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void minimumOperations ( int A [ ] , int n ) { int cnt = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( A [ i ] != ( i + 1 ) ) { if ( ( ( i - 1 ) >= 0 ) && A [ i - 1 ] == ( i + 1 ) ) { cnt ++ ; int t = A [ i ] ; A [ i ] = A [ i - 1 ] ; A [ i - 1 ] = t ; } else if ( ( ( i - 2 ) >= 0 ) && A [ i - 2 ] == ( i + 1 ) ) { cnt += 2 ; A [ i - 2 ] = A [ i - 1 ] ; A [ i - 1 ] = A [ i ] ; A [ i ] = i + 1 ; } else { System . out . println ( - 1 ) ; return ; } } } System . out . println ( cnt ) ; } public static void main ( String [ ] args ) { int A [ ] = { 7 , 3 , 2 , 1 , 4 } ; int n = A . length ; minimumOperations ( A , n ) ; } }

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void countOccurrences ( int n , int x ) { int count = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { if ( x % i == 0 ) { if ( x / i <= n ) count ++ ; } } System . out . print ( count ) ; } public static void main ( String [ ] args ) { int N = 7 , X = 12 ; countOccurrences ( N , X ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void ConvertArray ( int arr [ ] , int N ) { if ( N == 1 ) { System . out . println ( " Operation ▁ 1 ▁ : ▁ " + 1 + " ▁ " + 1 ) ; System . out . println ( " Added ▁ elements : ▁ " + - 1 * arr [ 0 ] ) ; System . out . println ( ) ; System . out . println ( " Operation ▁ 2 ▁ : ▁ " + 1 + " ▁ " + 1 ) ; System . out . println ( " Added ▁ elements : ▁ " + 1 * arr [ 0 ] ) ; System . out . println ( ) ; System . out . println ( " Operation ▁ 3 ▁ : ▁ " + 1 + " ▁ " + 1 ) ; System . out . println ( " Added ▁ elements : ▁ " + - 1 * arr [ 0 ] ) ; } else { System . out . println ( " Operation ▁ 1 ▁ : ▁ " + 1 + " ▁ " + N ) ; System . out . print ( " Added ▁ elements : ▁ " ) ; for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( - 1 * arr [ i ] * N + " ▁ " ) ; } System . out . println ( ) ; System . out . println ( ) ; System . out . println ( " Operation ▁ 2 ▁ : ▁ " + 1 + " ▁ " + ( N - 1 ) ) ; System . out . print ( " Added ▁ elements : ▁ " ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { System . out . print ( arr [ i ] * ( N - 1 ) + " ▁ " ) ; } System . out . println ( ) ; System . out . println ( ) ; System . out . println ( " Operation ▁ 3 ▁ : ▁ " + N + " ▁ " + N ) ; System . out . print ( " Added ▁ elements : ▁ " ) ; System . out . println ( arr [ N - 1 ] * ( N - 1 ) ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 2 , 4 } ; int N = arr . length ; ConvertArray ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX = 1000000 ; static void countOfPrimefactors ( int [ ] CountDistinct ) { 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 ; } } } } static int CountEvenPair ( int A [ ] , int B [ ] , int N , int M ) { int [ ] countDistinct = new int [ ( MAX + 1 ) ] ; countOfPrimefactors ( countDistinct ) ; int evenCount = 0 ; int oddCount = 0 ; int evenPairs = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( countDistinct [ B [ i ] ] == 0 ) continue ; if ( ( countDistinct [ B [ i ] ] & 1 ) != 0 ) { oddCount ++ ; } else { evenCount ++ ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( countDistinct [ A [ i ] ] == 0 ) continue ; if ( ( countDistinct [ A [ i ] ] & 1 ) != 0 ) { evenPairs += ( evenCount ) ; } else { evenPairs += evenCount + oddCount ; } } return evenPairs ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 3 } ; int B [ ] = { 4 , 5 , 6 } ; int N = A . length ; int M = B . length ; System . out . println ( CountEvenPair ( A , B , N , M ) ) ; } }

Index/key variables: i, j
Accumulator variables: evenCount, evenPairs, i, j, oddCount
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int longestSubarray ( int [ ] arr , int N , int K ) { HashMap < Integer , Integer > um = new HashMap < Integer , Integer > ( ) ; int sum = 0 , maxLen = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; if ( sum == K ) maxLen = i + 1 ; if ( ! um . containsKey ( sum ) ) um . put ( sum , i ) ; if ( um . containsKey ( sum - K ) ) { if ( maxLen < ( i - um . get ( sum - K ) ) ) maxLen = i - um . get ( sum - K ) ; } } return maxLen ; } static void minRequiredOperation ( int [ ] arr , int N , int K ) { int TotalSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) TotalSum += arr [ i ] ; int maxLen = longestSubarray ( arr , N , TotalSum - K ) ; if ( maxLen == - 1 ) { System . out . println ( - 1 ) ; } else System . out . println ( N - maxLen ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 1 , 1 , 2 } ; int K = 4 ; int N = arr . length ; minRequiredOperation ( arr , N , K ) ; } }

Index/key variables: i
Accumulator variables: TotalSum, i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void minimumDeletions ( String s ) { int n = s . length ( ) ; int ans = n ; for ( int i = n - 1 ; i >= 0 ; i -- ) { int t = s . charAt ( i ) - '0' ; if ( t % 2 == 0 ) { for ( int j = i - 1 ; j >= 0 ; j -- ) { int num = ( s . charAt ( j ) - '0' ) * 10 + t ; if ( num % 4 == 0 ) { int k1 = i - j - 1 ; int k2 = n - i - 1 ; ans = Math . min ( ans , k1 + k2 ) ; } } } } if ( ans == n ) { for ( int i = 0 ; i < n ; i ++ ) { int num = s . charAt ( i ) - '0' ; if ( num % 4 == 0 ) { ans = n - 1 ; } } } System . out . println ( ans ) ; } static public void main ( String [ ] args ) { String str = "12367" ; minimumDeletions ( str ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void generateSequence ( int arr [ ] , int n ) { String ans ; ans = Integer . toString ( arr [ 0 ] ) ; if ( n == 1 ) System . out . println ( ans ) ; else if ( n == 2 ) { System . out . println ( ans + " / " + Integer . toString ( arr [ 1 ] ) ) ; } else { ans += " / ( " + Integer . toString ( arr [ 1 ] ) ; for ( int i = 2 ; i < n ; i ++ ) { ans += " / " + Integer . toString ( arr [ i ] ) ; } ans += " ) " ; System . out . println ( ans ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1000 , 100 , 10 , 2 } ; int N = arr . length ; generateSequence ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void LCMPairs ( int arr [ ] , int N ) { int total_pairs = ( N * ( N - 1 ) ) / 2 ; int odd = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) odd ++ ; } odd = ( odd * ( odd - 1 ) ) / 2 ; System . out . println ( " Even ▁ = ▁ " + ( total_pairs - odd ) + " , ▁ Odd ▁ = ▁ " + odd ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 6 , 5 , 4 } ; int N = arr . length ; LCMPairs ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, odd
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int printNumber ( int N , int K , int M ) { int sum = K * ( M * ( M + 1 ) / 2 ) ; return sum - N ; } public static void main ( String [ ] args ) { int N = 17 ; int K = 3 ; int M = 4 ; System . out . print ( printNumber ( N , K , M ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void countEvenOdd ( int L , int R ) { int range = R - L + 1 ; int even = ( range / 4 ) * 2 ; if ( ( L & 1 ) != 0 && ( range % 4 == 3 ) ) { even ++ ; } else if ( ( L & 1 ) == 0 && ( range % 4 != 0 ) ) { even ++ ; } System . out . print ( " Even ▁ = ▁ " + even + " , ▁ Odd ▁ = ▁ " + ( range - even ) ) ; } public static void main ( String [ ] args ) { int L = 2 , R = 7 ; countEvenOdd ( L , R ) ; } }

Accumulator variables: even
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void countSwaps ( String S , String T ) { int [ ] value = new int [ 26 ] ; for ( int i = 0 ; i < 26 ; i ++ ) value [ i ] = i + 1 ; int N = S . length ( ) ; int sum1 = 0 ; int sum2 = 0 ; boolean flag = false ; for ( int i = 0 ; i < N ; i ++ ) { sum1 += value [ S . charAt ( i ) - ' a ' ] ; sum2 += value [ T . charAt ( i ) - ' a ' ] ; if ( ( value [ S . charAt ( i ) - ' a ' ] % 2 == 0 && value [ T . charAt ( i ) - ' a ' ] % 2 == 1 ) || ( value [ S . charAt ( i ) - ' a ' ] % 2 == 1 && value [ T . charAt ( i ) - ' a ' ] % 2 == 0 ) ) flag = false ; } if ( sum1 % 2 == 1 && sum2 % 2 == 1 ) System . out . println ( "0NEW_LINE"); else if ( sum1 % 2 == 0 && sum2 % 2 == 0 ) { if ( flag ) System . out . println ( "1" ) ; else System . out . println ( " - 1" ) ; } else { System . out . println ( " - 1" ) ; } } public static void main ( String [ ] args ) { String S = " acd " ; String T = " dbf " ; countSwaps ( S , T ) ; } }

Index/key variables: i
Accumulator variables: i, sum1, sum2
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static boolean isPrime ( int N ) { if ( N <= 1 ) return false ; for ( int i = 2 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) return false ; } return true ; } static void countPrimeTuples ( int N ) { int count = 0 ; for ( int i = 2 ; i <= N ; i ++ ) { if ( isPrime ( i ) && isPrime ( i - 2 ) ) count ++ ; } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int N = 6 ; countPrimeTuples ( N ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void countPairs ( int A [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) if ( ( A [ i ] A [ j ] ) > ( A [ i ] & A [ j ] ) ) { count ++ ; } } System . out . println ( count ) ; } public static void main ( String args [ ] ) { int A [ ] = { 1 , 4 , 7 } ; int N = A . length ; countPairs ( A , N ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
public class GFG { static int maximumCandy ( int [ ] candies , int [ ] safety , int N , int M ) { int total = 0 ; int ans = Integer . MAX_VALUE ; boolean all_safe = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( candies [ i ] + M > safety [ i ] ) { all_safe = false ; ans = Math . min ( ans , safety [ i ] ) ; } else { ans = Math . min ( ans , candies [ i ] + M ) ; } total += candies [ i ] ; } if ( all_safe ) return total ; else return ans ; } public static void main ( String [ ] args ) { int A [ ] = { 4 , 5 , 2 , 3 } ; int B [ ] = { 8 , 13 , 6 , 4 } ; int M = 5 ; int N = A . length ; System . out . println ( maximumCandy ( A , B , N , M ) ) ; } }

Index/key variables: i
Accumulator variables: i, total
Iterator variables: i
Boolean variables: all_safe
Class/struct names: GFG
Java program:
public class GFG { static void checkArrays ( int arr1 [ ] , int arr2 [ ] , int N ) { int count = 0 ; boolean flag = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr1 [ i ] != arr2 [ i ] ) { if ( arr1 [ i ] == 0 ) count ++ ; else { count -- ; if ( count < 0 ) { flag = false ; break ; } } } } if ( ( flag && ( count == 0 ) ) == true ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 0 , 0 , 1 , 1 } ; int arr2 [ ] = { 1 , 1 , 0 , 0 } ; int N = arr1 . length ; checkArrays ( arr1 , arr2 , N ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void canArrayBeReduced ( int [ ] arr , int N ) { if ( N == 1 ) { System . out . print ( arr [ 0 ] ) ; return ; } if ( arr [ 0 ] < arr [ N - 1 ] ) { System . out . print ( arr [ N - 1 ] ) ; } else System . out . print ( " Not ▁ Possible " ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 6 , 5 , 2 , 4 , 1 , 3 , 7 } ; int N = arr . length ; canArrayBeReduced ( arr , N ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MinimumMoves ( int A [ ] , int B [ ] , int N ) { int totalOperations = 0 ; int carry = 0 ; int K = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { int nearestMultiple = ( int ) ( Math . ceil ( ( double ) ( A [ i ] + carry ) / ( double ) ( B [ i ] ) ) * B [ i ] ) ; K = nearestMultiple - ( A [ i ] + carry ) ; totalOperations += K ; carry += K ; } return totalOperations ; } public static void main ( String [ ] args ) { int A [ ] = { 3 , 4 , 5 , 2 , 5 , 5 , 9 } ; int B [ ] = { 1 , 1 , 9 , 6 , 3 , 8 , 7 } ; int N = A . length ; System . out . print ( MinimumMoves ( A , B , N ) + "NEW_LINE"); } }

Index/key variables: i
Accumulator variables: carry, i, totalOperations
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void minimumDeviation ( int A [ ] , int N ) { TreeSet < Integer > s = new TreeSet < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] % 2 == 0 ) s . add ( A [ i ] ) ; else s . add ( 2 * A [ i ] ) ; } int diff = s . last ( ) - s . first ( ) ; while ( ( s . last ( ) % 2 == 0 ) ) { int maxEl = s . last ( ) ; s . remove ( maxEl ) ; s . add ( maxEl / 2 ) ; diff = Math . min ( diff , s . last ( ) - s . first ( ) ) ; } System . out . print ( diff ) ; } public static void main ( String [ ] args ) { int A [ ] = { 4 , 1 , 5 , 20 , 3 } ; int N = A . length ; minimumDeviation ( A , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int findMaxNum ( int num ) { String binaryNumber = Integer . toBinaryString ( num ) ; String maxBinaryNumber = " " ; int count0 = 0 , count1 = 0 ; int N = binaryNumber . length ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( binaryNumber . charAt ( i ) == '1' ) { count1 ++ ; } else { count0 ++ ; } } for ( int i = 0 ; i < count1 ; i ++ ) { maxBinaryNumber += '1' ; } for ( int i = 0 ; i < count0 ; i ++ ) { maxBinaryNumber += '0' ; } return Integer . parseInt ( maxBinaryNumber , 2 ) ; } public static void main ( String [ ] args ) { int N = 11 ; System . out . println ( findMaxNum ( N ) ) ; } }

Accumulator variables: count0, count1, i, maxBinaryNumber
Iterator variables: i
Class/struct names: GFG