dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; class GFG { static int cntSubarr ( int arr [ ] , int N ) { int res = 0 ; int prefixXor = 0 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { prefixXor = arr [ i ] ; for ( int j = i + 1 ; j < N ; j ++ ) { prefixXor ^= arr [ j ] ; if ( prefixXor == 0 && ( j - i + 1 ) % 2 == 0 ) { res ++ ; } } } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 3 , 3 , 6 , 7 , 8 } ; int N = arr . length ; System . out . println ( cntSubarr ( arr , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, prefixXor, res
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int M = 1000000 ; static int cntSubXor ( int arr [ ] , int N ) { int prefixXor = 0 ; int [ ] Even = new int [ M ] ; int [ ] Odd = new int [ M ] ; int cntSub = 0 ; Odd [ 0 ] = 1 ; for ( int i = 0 ; i < N ; i ++ ) { prefixXor ^= arr [ i ] ; if ( i % 2 == 1 ) { cntSub += Odd [ prefixXor ] ; Odd [ prefixXor ] ++ ; } else { cntSub += Even [ prefixXor ] ; Even [ prefixXor ] ++ ; } } return cntSub ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 3 , 3 , 6 , 7 , 8 } ; int N = arr . length ; System . out . print ( cntSubXor ( arr , N ) ) ; } }

Index/key variables: M, i, prefixXor
Accumulator variables: cntSub, i, prefixXor
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int S ; static void findMaxSum ( int [ ] arr , int n , int [ ] min , int k ) { ArrayList < int [ ] > A = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { A . add ( new int [ ] { arr [ i ] , min [ i ] } ) ; } Collections . sort ( A , ( a , b ) -> b [ 0 ] - a [ 0 ] ) ; int K = 0 ; for ( int i = 0 ; i < n ; i ++ ) { S += Math . max ( A . get ( i ) [ 0 ] - K , A . get ( i ) [ 1 ] ) ; K += k ; } } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 5 , 2 , 1 } ; int [ ] min = { 3 , 2 , 1 , 3 } ; int N = arr . length ; int K = 3 ; S = 0 ; findMaxSum ( arr , N , min , K ) ; System . out . println ( S ) ; } }

Index/key variables: i
Accumulator variables: K, S, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . ArrayList ; import java . util . HashMap ; class GFG { static int minLength ( String a , String b ) { HashMap < Character , Integer > Char = new HashMap < > ( ) ; for ( int i = 0 ; i < b . length ( ) ; i ++ ) { Char . put ( b . charAt ( i ) , Char . getOrDefault ( b . charAt ( i ) , 0 ) + 1 ) ; } HashMap < Character , ArrayList < Integer > > CharacterIndex = new HashMap < > ( ) ; for ( int i = 0 ; i < a . length ( ) ; i ++ ) { char x = a . charAt ( i ) ; if ( Char . containsKey ( x ) ) { if ( CharacterIndex . get ( x ) == null ) { CharacterIndex . put ( x , new ArrayList < Integer > ( ) ) ; } CharacterIndex . get ( x ) . add ( i ) ; } } int len = Integer . MAX_VALUE ; int flag ; while ( true ) { flag = 1 ; int firstVar = 0 , lastVar = 0 ; for ( int i = 0 ; i < b . length ( ) ; i ++ ) { if ( i == 0 ) { if ( CharacterIndex . containsKey ( i ) ) { flag = 0 ; break ; } else { int x = CharacterIndex . get ( b . charAt ( i ) ) . get ( 0 ) ; CharacterIndex . get ( b . charAt ( i ) ) . remove ( CharacterIndex . get ( b . charAt ( i ) ) . get ( 0 ) ) ; firstVar = x ; lastVar = x ; } } else { int elementFound = 0 ; for ( var e : CharacterIndex . get ( b . charAt ( i ) ) ) { if ( e > lastVar ) { elementFound = 1 ; lastVar = e ; break ; } } if ( elementFound == 0 ) { flag = 0 ; break ; } } } if ( flag == 0 ) { break ; } len = Math . min ( len , Math . abs ( lastVar - firstVar ) + 1 ) ; } return len ; } public static void main ( String [ ] args ) { String a = " abcdefababaef " ; String b = " abf " ; int len = minLength ( a , b ) ; if ( len != Integer . MAX_VALUE ) { System . out . println ( len ) ; } else { System . out . println ( " Impossible " ) ; } } }

Accumulator variables: i
Iterator variables: e, i
Class/struct names: GFG
Java program:
class GFG { static boolean is_prime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) return false ; } return true ; } static void countSmallerPrimes ( int ar [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int count = 0 ; for ( int j = i + 1 ; j < N ; j ++ ) { if ( ar [ j ] <= ar [ i ] && is_prime ( ar [ j ] ) ) { count ++ ; } } System . out . print ( count + " ▁ " ) ; } } public static void main ( String [ ] args ) { int ar [ ] = { 43 , 3 , 5 , 7 , 2 , 41 } ; int N = ar . length ; countSmallerPrimes ( ar , N ) ; } }

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 { static boolean checkConcat ( String str1 , String str2 ) { int N = str1 . length ( ) ; int M = str2 . length ( ) ; if ( N % M != 0 ) { return false ; } for ( int i = 0 ; i < N ; i ++ ) { if ( str1 . charAt ( i ) != str2 . charAt ( i % M ) ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String str1 = " abcabcabc " ; String str2 = " abc " ; if ( checkConcat ( str1 , str2 ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int MinLen ( String str , int K ) { int N = str . length ( ) ; int i = 0 ; while ( i < N - 1 ) { if ( str . charAt ( i ) != str . charAt ( i + 1 ) ) { break ; } i ++ ; } if ( i == N - 1 ) { return N ; } return Math . max ( 1 , N - K ) ; } public static void main ( String [ ] args ) { String str = " aabc " ; int K = 1 ; System . out . print ( MinLen ( str , K ) ) ; } }

Accumulator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static double temp ( int n , int x ) { return Math . pow ( x * 1.0 / n , n ) ; } static boolean check ( int n , int y , int x ) { double v = temp ( n , x ) ; return ( v >= y ) ; } static void find ( int x , int y ) { int high = ( int ) Math . floor ( x / Math . exp ( 1.0 ) ) ; int low = 1 ; if ( x == y ) System . out . print ( 1 + "NEW_LINE"); else if ( ! check ( high , y , x ) ) System . out . print ( - 1 + "NEW_LINE"); else { while ( high - low > 1 ) { int mid = ( high + low ) / 2 ; if ( check ( mid , y , x ) ) high = mid ; else low = mid ; } System . out . print ( high + "NEW_LINE"); } } public static void main ( String [ ] args ) { int x = 9 , y = 8 ; find ( x , y ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Map < Integer , Vector < Integer > > M ; static class node { int data ; node left ; node right ; public node ( ) { } public node ( int data , node left , node right ) { super ( ) ; this . data = data ; this . left = left ; this . right = right ; } } ; static node newnode ( int d ) { node temp = new node ( ) ; temp . data = d ; temp . left = null ; temp . right = null ; return temp ; } static void dfs ( node root , int l ) { if ( root == null ) return ; if ( ! M . containsKey ( l ) ) { Vector < Integer > temp = new Vector < Integer > ( ) ; temp . add ( root . data ) ; M . put ( l , temp ) ; } else M . get ( l ) . add ( root . data ) ; dfs ( root . left , l + 1 ) ; dfs ( root . right , l + 1 ) ; } static void printMidNodes ( node root ) { M = new HashMap < Integer , Vector < Integer > > ( ) ; dfs ( root , 0 ) ; for ( Map . Entry < Integer , Vector < Integer > > it : M . entrySet ( ) ) { int size = it . getValue ( ) . size ( ) ; if ( size % 2 == 1 ) { System . out . print ( it . getValue ( ) . get ( ( size - 1 ) / 2 ) + "NEW_LINE"); } else { System . out . print ( it . getValue ( ) . get ( ( size - 1 ) / 2 ) + " ▁ " + it . getValue ( ) . get ( ( ( size - 1 ) / 2 ) + 1 ) + "NEW_LINE"); } } } public static void main ( String [ ] args ) { node root = newnode ( 1 ) ; root . left = newnode ( 2 ) ; root . right = newnode ( 3 ) ; root . left . left = newnode ( 4 ) ; root . left . right = newnode ( 5 ) ; root . left . right . left = newnode ( 11 ) ; root . left . right . right = newnode ( 6 ) ; root . left . right . right . left = newnode ( 7 ) ; root . left . right . right . right = newnode ( 9 ) ; root . right . left = newnode ( 10 ) ; root . right . right = newnode ( 8 ) ; printMidNodes ( root ) ; } }

Class/struct names: GFG, node
Java program:
import java . io . * ; class GFG { static int minLength ( int arr [ ] , int N ) { for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ 0 ] != arr [ i ] ) { return 1 ; } } return N ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 1 , 3 , 1 } ; int N = arr . length ; System . out . print ( minLength ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class node { node left ; node right ; } ; static void insert ( int x , node head ) { node curr = head ; for ( int i = 30 ; i >= 0 ; i -- ) { int val = ( x >> i ) & 1 ; if ( val == 0 ) { if ( curr . left == null ) curr . left = new node ( ) ; curr = curr . left ; } else { if ( curr . right == null ) curr . right = new node ( ) ; curr = curr . right ; } } } static int findMaximumXOR ( int arr [ ] , int n ) { node head = new node ( ) ; for ( int i = 0 ; i < n ; i ++ ) { insert ( arr [ i ] , head ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int curr_xor = 0 ; int M = ( int ) Math . pow ( 2 , 30 ) ; node curr = head ; for ( int j = 30 ; j >= 0 ; j -- ) { int val = ( arr [ i ] >> j ) & 1 ; if ( val == 0 ) { if ( curr . right != null ) { curr_xor += M ; curr = curr . right ; } else { curr = curr . left ; } } else { if ( curr . left != null ) { curr_xor += M ; curr = curr . left ; } else { curr = curr . right ; } } M /= 2 ; } ans = Math . max ( ans , curr_xor ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = arr . length ; System . out . print ( findMaximumXOR ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: M, curr_xor, i, j
Iterator variables: i, j
Class/struct names: GFG, node
Java program:
import java . io . * ; class GFG { static void PrintIndexes ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { int currSubSum = 0 ; for ( int j = i ; j < N ; j ++ ) { currSubSum += arr [ j ] ; int sq = ( int ) Math . sqrt ( currSubSum ) ; if ( sq * sq == currSubSum ) { System . out . print ( " ( " + i + " , " + j + " ) " + " ▁ " ) ; } } } } public static void main ( String [ ] args ) throws java . lang . Exception { int arr [ ] = { 65 , 79 , 81 } ; PrintIndexes ( arr , arr . length ) ; } }

Index/key variables: j
Accumulator variables: currSubSum, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int countPosition ( int [ ] [ ] mat ) { int n = mat . length ; int m = mat [ 0 ] . length ; int [ ] row = new int [ n ] ; int [ ] col = new int [ m ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { col [ j ] ++ ; row [ i ] ++ ; } } } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( row [ i ] == col [ j ] ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 0 , 1 } , { 1 , 1 } } ; System . out . println ( countPosition ( mat ) ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void maxAtLevel ( int N , int M , int [ ] Value , int Edges [ ] [ ] ) { Vector < Integer > [ ] adj = new Vector [ N ] ; for ( int i = 0 ; i < adj . length ; i ++ ) adj [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; adj [ u ] . add ( v ) ; } Queue < Integer > q = new LinkedList < > ( ) ; q . add ( 0 ) ; while ( ! q . isEmpty ( ) ) { int count = q . size ( ) ; int maxVal = 0 ; while ( count -- > 0 ) { int temp = q . peek ( ) ; q . remove ( ) ; maxVal = Math . max ( maxVal , Value [ temp ] ) ; for ( int i = 0 ; i < adj [ temp ] . size ( ) ; i ++ ) { q . add ( adj [ temp ] . get ( i ) ) ; } } System . out . print ( maxVal + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 10 ; int Edges [ ] [ ] = { { 0 , 1 } , { 0 , 2 } , { 0 , 3 } , { 1 , 4 } , { 1 , 5 } , { 3 , 6 } , { 6 , 7 } , { 6 , 8 } , { 6 , 9 } } ; int [ ] Value = { 1 , 2 , - 1 , 3 , 4 , 5 , 8 , 6 , 12 , 7 } ; maxAtLevel ( N , N - 1 , Value , Edges ) ; } }

Index/key variables: N, i, temp, u
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . Arrays ; class GFG { static void ctTriplets ( int arr [ ] , int N ) { Arrays . sort ( arr ) ; int [ ] temp = new int [ N ] ; int index = 0 ; for ( int i = 1 ; i < N ; i += 2 ) { temp [ i ] = arr [ index ++ ] ; } for ( int i = 0 ; i < N ; i += 2 ) { temp [ i ] = arr [ index ++ ] ; } int ct = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i > 0 && i + 1 < N ) { if ( temp [ i ] < temp [ i + 1 ] && temp [ i ] < temp [ i - 1 ] ) { ct ++ ; } } } System . out . println ( " Count ▁ of ▁ triplets : " + ct ) ; System . out . print ( " Array : " ) ; for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( temp [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int N = arr . length ; ctTriplets ( arr , N ) ; } }

Index/key variables: N, i
Accumulator variables: ct, i, index
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; import java . math . * ; class GFG { public static boolean check ( int [ ] a , int n ) { int [ ] b = new int [ n ] ; int minElement = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = a [ i ] ; minElement = Math . min ( minElement , a [ i ] ) ; } Arrays . sort ( b ) ; int k = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] != b [ i ] && a [ i ] % minElement != 0 ) { k = 0 ; break ; } } return k == 1 ? true : false ; } public static void main ( String [ ] args ) { int [ ] a = { 4 , 3 , 6 , 6 , 2 , 9 } ; int n = a . length ; if ( check ( a , n ) == true ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int numSpecial ( int [ ] [ ] mat ) { int m = mat . length ; int n = mat [ 0 ] . length ; int [ ] rows = new int [ m ] ; int [ ] cols = new int [ n ] ; int i , j ; for ( i = 0 ; i < m ; i ++ ) { rows [ i ] = 0 ; for ( j = 0 ; j < n ; j ++ ) rows [ i ] += mat [ i ] [ j ] ; } for ( i = 0 ; i < n ; i ++ ) { cols [ i ] = 0 ; for ( j = 0 ; j < m ; j ++ ) cols [ i ] += mat [ j ] [ i ] ; } int cnt = 0 ; for ( i = 0 ; i < m ; i ++ ) { for ( j = 0 ; j < n ; j ++ ) { if ( mat [ i ] [ j ] == 1 && rows [ i ] == 1 && cols [ j ] == 1 ) cnt ++ ; } } return cnt ; } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 1 , 0 , 0 } , { 0 , 0 , 1 } , { 0 , 0 , 0 } } ; System . out . print ( numSpecial ( mat ) + "NEW_LINE"); } }

Index/key variables: i, j, m, n
Accumulator variables: cnt, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static Vector < Integer > minmaxNumbers ( int [ ] [ ] matrix , Vector < Integer > res ) { Set < Integer > set = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < matrix . length ; i ++ ) { int minr = Integer . MAX_VALUE ; for ( int j = 0 ; j < matrix [ i ] . length ; j ++ ) { minr = Math . min ( minr , matrix [ i ] [ j ] ) ; } set . add ( minr ) ; } for ( int j = 0 ; j < matrix [ 0 ] . length ; j ++ ) { int maxc = Integer . MIN_VALUE ; for ( int i = 0 ; i < matrix . length ; i ++ ) { maxc = Math . max ( maxc , matrix [ i ] [ j ] ) ; } if ( set . contains ( maxc ) ) { res . add ( maxc ) ; } } return res ; } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 1 , 10 , 4 } , { 9 , 3 , 8 } , { 15 , 16 , 17 } } ; Vector < Integer > ans = new Vector < Integer > ( ) ; ans = minmaxNumbers ( mat , ans ) ; if ( ans . size ( ) == 0 ) System . out . println ( " - 1" ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) System . out . println ( ans . get ( i ) ) ; } }

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 int mini = 105 , ans , n ; static Vector < Integer > [ ] g = new Vector [ 100 ] ; static int [ ] size = new int [ 100 ] ; static void create_graph ( ) { g [ 1 ] . add ( 2 ) ; g [ 2 ] . add ( 1 ) ; g [ 1 ] . add ( 3 ) ; g [ 3 ] . add ( 1 ) ; g [ 1 ] . add ( 4 ) ; g [ 4 ] . add ( 1 ) ; g [ 2 ] . add ( 5 ) ; g [ 5 ] . add ( 2 ) ; g [ 2 ] . add ( 6 ) ; g [ 6 ] . add ( 2 ) ; } static void dfs ( int node , int parent ) { size [ node ] = 1 ; int mx = 0 ; for ( int y : g [ node ] ) { if ( y == parent ) continue ; dfs ( y , node ) ; size [ node ] += size [ y ] ; mx = Math . max ( mx , size [ y ] ) ; } mx = Math . max ( mx , n - size [ node ] ) ; if ( mx < mini ) { mini = mx ; ans = node ; } } public static void main ( String [ ] args ) { n = 6 ; for ( int i = 0 ; i < g . length ; i ++ ) g [ i ] = new Vector < Integer > ( ) ; create_graph ( ) ; dfs ( 1 , - 1 ) ; System . out . print ( ans + "NEW_LINE"); } }

Index/key variables: i, node, y
Accumulator variables: i
Iterator variables: i, y
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minOperation ( String s ) { int n = s . length ( ) ; int temp1 = - 1 , temp2 = - 1 ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int curr = s . charAt ( i ) ; if ( curr == '0' ) { if ( temp1 == - 1 && temp2 == - 1 ) { temp1 = i ; } else if ( temp1 != - 1 && temp2 == - 1 && i - temp1 == 1 ) { temp2 = i ; } else if ( temp1 != - 1 ) { temp1 = - 1 ; ans ++ ; } else if ( temp1 == - 1 && temp2 != - 1 && i - temp2 != 1 ) { temp2 = - 1 ; ans ++ ; } } } if ( temp1 != - 1 && temp2 != - 1 ) { ans += 2 ; } else if ( temp1 != - 1 temp2 != - 1 ) { ans += 1 ; } return ans ; } public static void main ( String [ ] args ) { String s = "110010" ; System . out . println ( minOperation ( s ) ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { static int findMinLength ( int [ ] arr ) { int index = ( int ) arr . length - 1 ; while ( index > 0 && arr [ index ] >= arr [ index - 1 ] ) { index -- ; } return index ; } public static void main ( String args [ ] ) { int arr [ ] = { 7 , 8 , 5 , 0 , - 1 , - 1 , 0 , 1 , 2 , 3 , 4 } ; int n = arr . length ; System . out . println ( findMinLength ( arr ) ) ; } }

Index/key variables: index
Accumulator variables: index
Class/struct names: GFG
Java program:
class GFG { static int countPrecedingK ( int a [ ] , int n , int K ) { int [ ] prefix = new int [ n ] ; prefix [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + a [ i ] ; } int ctr = 0 ; if ( prefix [ K - 1 ] < a [ K ] ) ctr ++ ; for ( int i = K + 1 ; i < n ; i ++ ) { if ( prefix [ i - 1 ] - prefix [ i - K - 1 ] < a [ i ] ) ctr ++ ; } return ctr ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 8 , 10 , - 2 , 7 , 5 , 5 , 9 , 15 } ; int N = arr . length ; int K = 2 ; System . out . print ( countPrecedingK ( arr , N , K ) ) ; } }

Index/key variables: K, i, n
Accumulator variables: ctr, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void convertBfromA ( int a , int b ) { int moves = 0 ; int x = Math . abs ( a - b ) ; for ( int i = 10 ; i > 0 ; i -- ) { moves += x / i ; x = x % i ; } System . out . print ( moves + " ▁ " ) ; } public static void main ( String [ ] args ) { int A = 188 , B = 4 ; convertBfromA ( A , B ) ; } }

Accumulator variables: i, moves
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static final int M = 1000 ; static int countNum ( int N , int sum , int K , int st , int dp [ ] [ ] [ ] ) { if ( N == 0 && sum == 0 ) { return 1 ; } if ( N < 0 ) { return 0 ; } if ( dp [ N ] [ sum ] [ st ] != - 1 ) { return dp [ N ] [ sum ] [ st ] ; } int res = 0 ; int start = st == 1 ? 0 : 1 ; for ( int i = start ; i <= 9 ; i ++ ) { res += countNum ( N - 1 , ( sum + i ) % K , K , ( ( st i ) > 0 ) ? 1 : 0 , dp ) ; } return dp [ N ] [ sum ] [ st ] = res ; } public static void main ( String [ ] args ) { int N = 2 , K = 7 ; int [ ] [ ] [ ] dp = new int [ M ] [ M ] [ 2 ] ; for ( int [ ] [ ] i : dp ) for ( int [ ] j : i ) Arrays . fill ( j , - 1 ) ; System . out . print ( countNum ( N , 0 , K , 0 , dp ) ) ; } }

Index/key variables: M, N, st, sum
Accumulator variables: i, res
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int smallestNth ( int A , int B , int N ) { int res = Integer . MAX_VALUE ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = N ; j > i ; j -- ) { if ( ( B - A ) % ( j - i ) == 0 ) { int D = ( B - A ) / ( j - i ) ; int FirstTerm = A - ( i - 1 ) * D ; int NthTerm = FirstTerm + ( N - 1 ) * D ; if ( FirstTerm > 0 ) res = Math . min ( res , NthTerm ) ; } } } return res ; } public static void main ( String [ ] args ) { int N = 3 ; int A = 1 ; int B = 6 ; System . out . print ( smallestNth ( A , B , N ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void sieve ( boolean prime [ ] ) { for ( int i = 0 ; i < 1000000 ; i ++ ) { prime [ i ] = true ; } prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i * i <= 1000000 ; i ++ ) { if ( prime [ i ] ) { for ( int j = i * i ; j < 1000000 ; j += i ) { prime [ j ] = false ; } } } } static void subPrimeSum ( int N , int K , int arr [ ] , boolean prime [ ] ) { int currSum = 0 ; for ( int i = 0 ; i < K ; i ++ ) { currSum += arr [ i ] ; } if ( prime [ currSum ] ) { for ( int i = 0 ; i < K ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } return ; } int st = 1 , en = K ; while ( en < N ) { currSum += arr [ en ] - arr [ st - 1 ] ; if ( prime [ currSum ] ) { for ( int i = st ; i <= en ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } return ; } en ++ ; st ++ ; } } public static void main ( String [ ] args ) { int arr [ ] = { 20 , 7 , 5 , 4 , 3 , 11 , 99 , 87 , 23 , 45 } ; int K = 4 ; int N = arr . length ; boolean [ ] prime = new boolean [ 1000000 ] ; sieve ( prime ) ; subPrimeSum ( N , K , arr , prime ) ; } }

Index/key variables: currSum, en, i, j
Accumulator variables: currSum, en, i, j, st
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int minDeletion ( String str ) { int n = str . length ( ) ; int firstIdx1 = - 1 ; int lastIdx0 = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == '1' ) { firstIdx1 = i ; break ; } } for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( str . charAt ( i ) == '0' ) { lastIdx0 = i ; break ; } } if ( firstIdx1 == - 1 lastIdx0 == - 1 ) return 0 ; int count1 = 0 , count0 = 0 ; for ( int i = 0 ; i < lastIdx0 ; i ++ ) { if ( str . charAt ( i ) == '1' ) { count1 ++ ; } } for ( int i = firstIdx1 + 1 ; i < n ; i ++ ) { if ( str . charAt ( i ) == '1' ) { count0 ++ ; } } return Math . min ( count0 , count1 ) ; } public static void main ( String [ ] args ) { String str = "1000101" ; System . out . println ( minDeletion ( str ) ) ; } }

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