dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { static int getEndingIndex ( String str , int n , int i ) { i ++ ; while ( i < n ) { char curr = str . charAt ( i ) ; char prev = str . charAt ( i - 1 ) ; if ( ( curr == ' a ' && prev == ' z ' ) || ( curr - prev == 1 ) ) i ++ ; else break ; } return i - 1 ; } static int largestSubStr ( String str , int n ) { int len = 0 ; int i = 0 ; while ( i < n ) { int end = getEndingIndex ( str , n , i ) ; len = Math . max ( end - i + 1 , len ) ; i = end + 1 ; } return len ; } public static void main ( String args [ ] ) { String str = " abcabcdefabc " ; int n = str . length ( ) ; System . out . print ( largestSubStr ( str , n ) ) ; } }

Accumulator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static long getSum ( long n , int d ) { if ( n < d ) return 0 ; while ( n % 10 != d ) n -- ; long k = n / 10 ; return ( k + 1 ) * d + ( k * 10 + 10 * k * k ) / 2 ; } public static void main ( String [ ] args ) { long n = 30 ; int d = 3 ; System . out . println ( getSum ( n , d ) ) ; } }

Accumulator variables: n
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { static HashMap < Integer , Integer > getFrequencyMap ( int arr [ ] ) { HashMap < Integer , Integer > hashMap = new HashMap < > ( ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( hashMap . containsKey ( arr [ i ] ) ) { hashMap . put ( arr [ i ] , hashMap . get ( arr [ i ] ) + 1 ) ; } else { hashMap . put ( arr [ i ] , 1 ) ; } } return hashMap ; } static boolean hasDigit ( HashMap < Integer , Integer > hashMap , int digit ) { if ( hashMap . containsKey ( digit ) && hashMap . get ( digit ) > 0 ) { hashMap . put ( digit , hashMap . get ( digit ) - 1 ) ; return true ; } return false ; } static String getMaxTime ( int arr [ ] ) { HashMap < Integer , Integer > hashMap = getFrequencyMap ( arr ) ; int i ; boolean flag ; String time = " " ; flag = false ; for ( i = 2 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } if ( ! flag ) { return " - 1" ; } flag = false ; if ( time . charAt ( 0 ) == '2' ) { for ( i = 3 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } } else { for ( i = 9 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } } if ( ! flag ) { return " - 1" ; } time += " : " ; flag = false ; for ( i = 5 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } if ( ! flag ) { return " - 1" ; } flag = false ; for ( i = 9 ; i >= 0 ; i -- ) { if ( hasDigit ( hashMap , i ) ) { flag = true ; time += i ; break ; } } if ( ! flag ) { return " - 1" ; } return time ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 0 , 0 , 9 } ; System . out . println ( getMaxTime ( arr ) ) ; } }

Index/key variables: i
Accumulator variables: i, time
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . util . HashMap ; class GFG { static String smallestFreq ( String S1 , String S2 ) { HashMap < String , Integer > banned = new HashMap < > ( ) ; for ( int i = 0 ; i < S2 . length ( ) ; i ++ ) { String s = " " ; while ( i < S2 . length ( ) && S2 . charAt ( i ) != ' ▁ ' ) s += S2 . charAt ( i ++ ) ; banned . put ( s , banned . get ( s ) == null ? 1 : banned . get ( s ) + 1 ) ; } HashMap < String , Integer > result = new HashMap < > ( ) ; String ans = " " ; int freq = 0 ; for ( int i = 0 ; i < S1 . length ( ) ; i ++ ) { String s = " " ; while ( i < S1 . length ( ) && S1 . charAt ( i ) != ' ▁ ' ) s += S1 . charAt ( i ++ ) ; if ( banned . get ( s ) == null ) { result . put ( s , result . get ( s ) == null ? 1 : result . get ( s ) + 1 ) ; if ( result . get ( s ) > freq || ( result . get ( s ) == freq && s . compareTo ( ans ) < 0 ) ) { ans = s ; freq = result . get ( s ) ; } } } return ans ; } public static void main ( String [ ] args ) { String S1 = " geeks ▁ for ▁ geeks ▁ is ▁ best ▁ place ▁ to ▁ learn " ; String S2 = " bad ▁ place " ; System . out . println ( smallestFreq ( S1 , S2 ) ) ; } }

Accumulator variables: i, s
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int replace ( String A , String B ) { int n = A . length ( ) , m = B . length ( ) ; int count = 0 , i , j ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( i + j >= n ) break ; else if ( A . charAt ( i + j ) != B . charAt ( j ) ) break ; } if ( j == m ) { count ++ ; i += m - 1 ; } } return count ; } public static void main ( String args [ ] ) { String str1 = " aaaaaaaa " ; String str2 = " aaa " ; System . out . println ( replace ( str1 , str2 ) ) ; } }

Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static final int n = 6 ; static final int m = 8 ; static final int visited [ ] [ ] = new int [ n ] [ m ] ; static final int result [ ] [ ] = new int [ n ] [ m ] ; static int COUNT ; static boolean is_valid ( int x , int y , int key , int input [ ] [ ] ) { if ( x < n && y < m && x >= 0 && y >= 0 ) { if ( visited [ x ] [ y ] == 0 && input [ x ] [ y ] == key ) return true ; else return false ; } else return false ; } static void BFS ( int x , int y , int i , int j , int input [ ] [ ] ) { if ( x != y ) return ; visited [ i ] [ j ] = 1 ; COUNT ++ ; int x_move [ ] = { 0 , 0 , 1 , - 1 } ; int y_move [ ] = { 1 , - 1 , 0 , 0 } ; for ( int u = 0 ; u < 4 ; u ++ ) if ( ( is_valid ( i + y_move [ u ] , j + x_move [ u ] , x , input ) ) == true ) BFS ( x , y , i + y_move [ u ] , j + x_move [ u ] , input ) ; } static void reset_visited ( ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) visited [ i ] [ j ] = 0 ; } static void reset_result ( int key , int input [ ] [ ] ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( visited [ i ] [ j ] == 1 && input [ i ] [ j ] == key ) result [ i ] [ j ] = visited [ i ] [ j ] ; else result [ i ] [ j ] = 0 ; } } } static void print_result ( int res ) { System . out . println ( " The ▁ largest ▁ connected ▁ " + " component ▁ of ▁ the ▁ grid ▁ is ▁ : " + res ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( result [ i ] [ j ] != 0 ) System . out . print ( result [ i ] [ j ] + " ▁ " ) ; else System . out . print ( " . ▁ " ) ; } System . out . println ( ) ; } } static void computeLargestConnectedGrid ( int input [ ] [ ] ) { int current_max = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { reset_visited ( ) ; COUNT = 0 ; if ( j + 1 < m ) BFS ( input [ i ] [ j ] , input [ i ] [ j + 1 ] , i , j , input ) ; if ( COUNT >= current_max ) { current_max = COUNT ; reset_result ( input [ i ] [ j ] , input ) ; } reset_visited ( ) ; COUNT = 0 ; if ( i + 1 < n ) BFS ( input [ i ] [ j ] , input [ i + 1 ] [ j ] , i , j , input ) ; if ( COUNT >= current_max ) { current_max = COUNT ; reset_result ( input [ i ] [ j ] , input ) ; } } } print_result ( current_max ) ; } public static void main ( String args [ ] ) { int input [ ] [ ] = { { 1 , 4 , 4 , 4 , 4 , 3 , 3 , 1 } , { 2 , 1 , 1 , 4 , 3 , 3 , 1 , 1 } , { 3 , 2 , 1 , 1 , 2 , 3 , 2 , 1 } , { 3 , 3 , 2 , 1 , 2 , 2 , 2 , 2 } , { 3 , 1 , 3 , 1 , 1 , 4 , 4 , 4 } , { 1 , 1 , 3 , 1 , 1 , 4 , 4 , 4 } } ; computeLargestConnectedGrid ( input ) ; } }

Index/key variables: i, j, m, n, u, x, y
Accumulator variables: COUNT, i, j, u
Iterator variables: i, j, u
Class/struct names: GFG
Java program:
class GFG { static int isSubstring ( String s1 , String s2 ) { int M = s1 . length ( ) ; int N = s2 . length ( ) ; for ( int i = 0 ; i <= N - M ; i ++ ) { int j ; for ( j = 0 ; j < M ; j ++ ) if ( s2 . charAt ( i + j ) != s1 . charAt ( j ) ) break ; if ( j == M ) return i ; } return - 1 ; } public static void main ( String args [ ] ) { String s1 = " for " ; String s2 = " geeksforgeeks " ; int res = isSubstring ( s1 , s2 ) ; if ( res == - 1 ) System . out . println ( " Not ▁ present " ) ; else System . out . println ( " Present ▁ at ▁ index ▁ " + res ) ; } }

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 split ( String str ) { int len = str . length ( ) ; if ( len == 1 ) { System . out . println ( " Not ▁ Possible " ) ; return ; } String s1 = " " , s2 = " " ; long num1 , num2 ; for ( int i = 0 ; i <= len / 2 ; i ++ ) { int flag = 0 ; s1 = str . substring ( 0 , i + 1 ) ; num1 = Long . parseLong ( ( s1 ) ) ; num2 = num1 + 1 ; s2 = Long . toString ( num2 ) ; int k = i + 1 ; while ( flag == 0 ) { int l = s2 . length ( ) ; if ( k + l > len ) { flag = 1 ; break ; } if ( ( str . substring ( k , k + l ) . equals ( s2 ) ) ) { flag = 0 ; num2 ++ ; k = k + l ; if ( k == len ) break ; s2 = Long . toString ( num2 ) ; l = s2 . length ( ) ; if ( k + 1 > len ) { flag = 1 ; break ; } } else flag = 1 ; } if ( flag == 0 ) { System . out . println ( " Possible " + " ▁ " + s1 ) ; break ; } else if ( flag == 1 && i > len / 2 - 1 ) { System . out . println ( " Not ▁ Possible " ) ; break ; } } } public static void main ( String args [ ] ) { Scanner in = new Scanner ( System . in ) ; String str = "99100" ; split ( str ) ; } }

Accumulator variables: i, num2
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int internalSearch ( String needle , int row , int col , String hay [ ] , int row_max , int col_max , int xx ) { int found = 0 ; if ( row >= 0 && row <= row_max && col >= 0 && col <= col_max && xx < needle . length ( ) && needle . charAt ( xx ) == hay [ row ] . charAt ( col ) ) { char match = needle . charAt ( xx ) ; xx += 1 ; hay [ row ] = hay [ row ] . substring ( 0 , col ) + "0" + hay [ row ] . substring ( col + 1 ) ; if ( xx == needle . length ( ) ) { found = 1 ; } else { found += internalSearch ( needle , row , col + 1 , hay , row_max , col_max , xx ) ; found += internalSearch ( needle , row , col - 1 , hay , row_max , col_max , xx ) ; found += internalSearch ( needle , row + 1 , col , hay , row_max , col_max , xx ) ; found += internalSearch ( needle , row - 1 , col , hay , row_max , col_max , xx ) ; } hay [ row ] = hay [ row ] . substring ( 0 , col ) + match + hay [ row ] . substring ( col + 1 ) ; } return found ; } static int searchString ( String needle , int row , int col , String str [ ] , int row_count , int col_count ) { int found = 0 ; int r , c ; for ( r = 0 ; r < row_count ; ++ r ) { for ( c = 0 ; c < col_count ; ++ c ) { found += internalSearch ( needle , r , c , str , row_count - 1 , col_count - 1 , 0 ) ; } } return found ; } public static void main ( String args [ ] ) { String needle = " MAGIC " ; String input [ ] = { " BBABBM " , " CBMBBA " , " IBABBG " , " GOZBBI " , " ABBBBC " , " MCIGAM " } ; String str [ ] = new String [ input . length ] ; int i ; for ( i = 0 ; i < input . length ; ++ i ) { str [ i ] = input [ i ] ; } System . out . println ( " count : ▁ " + searchString ( needle , 0 , 0 , str , str . length , str [ 0 ] . length ( ) ) ) ; } }

Index/key variables: i, row
Accumulator variables: found, xx
Iterator variables: c, i, r
Class/struct names: GFG
Java program:
class GFG { static void KMP ( int m , int n , String str2 , String str1 ) { int pos = 0 , len = 0 ; int [ ] p = new int [ m + 1 ] ; int k = 0 ; char [ ] ch1 = str1 . toCharArray ( ) ; char [ ] ch2 = str2 . toCharArray ( ) ; for ( int i = 2 ; i <= n ; i ++ ) { while ( k > 0 && ch1 [ k ] != ch1 [ i - 1 ] ) k = p [ k ] ; if ( ch1 [ k ] == ch1 [ i - 1 ] ) ++ k ; p [ i ] = k ; } for ( int j = 0 , i = 0 ; i < m ; i ++ ) { while ( j > 0 && j < n && ch1 [ j ] != ch2 [ i ] ) j = p [ j ] ; if ( j < n && ch1 [ j ] == ch2 [ i ] ) j ++ ; if ( j > len ) { len = j ; pos = i - j + 1 ; } } System . out . println ( " Shift ▁ = ▁ " + pos ) ; System . out . println ( " Prefix ▁ = ▁ " + str1 . substring ( 0 , len ) ) ; } public static void main ( String [ ] args ) { String str1 = " geeksforgeeks " ; String str2 = " forgeeksgeeks " ; int n = str1 . length ( ) ; str2 = str2 + str2 ; KMP ( 2 * n , n , str2 , str1 ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int patternCount ( String str ) { char last = str . charAt ( 0 ) ; int i = 1 , counter = 0 ; while ( i < str . length ( ) ) { if ( str . charAt ( i ) == '0' && last == '1' ) { while ( str . charAt ( i ) == '0' ) i ++ ; if ( str . charAt ( i ) == '1' ) counter ++ ; } last = str . charAt ( i ) ; i ++ ; } return counter ; } public static void main ( String [ ] args ) { String str = "1001ab010abc01001" ; System . out . println ( patternCount ( str ) ) ; } }

Accumulator variables: counter, i
Class/struct names: GFG
Java program:
class GFG { static void preprocess_strong_suffix ( int [ ] shift , int [ ] bpos , char [ ] pat , int m ) { int i = m , j = m + 1 ; bpos [ i ] = j ; while ( i > 0 ) { while ( j <= m && pat [ i - 1 ] != pat [ j - 1 ] ) { if ( shift [ j ] == 0 ) shift [ j ] = j - i ; j = bpos [ j ] ; } i -- ; j -- ; bpos [ i ] = j ; } } static void preprocess_case2 ( int [ ] shift , int [ ] bpos , char [ ] pat , int m ) { int i , j ; j = bpos [ 0 ] ; for ( i = 0 ; i <= m ; i ++ ) { if ( shift [ i ] == 0 ) shift [ i ] = j ; if ( i == j ) j = bpos [ j ] ; } } static void search ( char [ ] text , char [ ] pat ) { int s = 0 , j ; int m = pat . length ; int n = text . length ; int [ ] bpos = new int [ m + 1 ] ; int [ ] shift = new int [ m + 1 ] ; for ( int i = 0 ; i < m + 1 ; i ++ ) shift [ i ] = 0 ; preprocess_strong_suffix ( shift , bpos , pat , m ) ; preprocess_case2 ( shift , bpos , pat , m ) ; while ( s <= n - m ) { j = m - 1 ; while ( j >= 0 && pat [ j ] == text [ s + j ] ) j -- ; if ( j < 0 ) { System . out . printf ( "pattern occurs at shift = %dNEW_LINE", s); s += shift [ 0 ] ; } else s += shift [ j + 1 ] ; } } public static void main ( String [ ] args ) { char [ ] text = " ABAAAABAACD " . toCharArray ( ) ; char [ ] pat = " ABA " . toCharArray ( ) ; search ( text , pat ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, s
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static int maxPrefix ( String s , String t ) { int count = 0 ; for ( int i = 0 ; i < t . length ( ) ; i ++ ) { if ( count == s . length ( ) ) break ; if ( t . charAt ( i ) == s . charAt ( count ) ) count ++ ; } return count ; } public static void main ( String args [ ] ) { String S = " digger " ; String T = " biggerdiagram " ; System . out . println ( maxPrefix ( S , T ) ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void translate ( char str [ ] ) { for ( int i = 1 ; i < str . length ; i ++ ) { if ( str [ i - 1 ] == ' A ' && str [ i ] == ' B ' ) { str [ i - 1 ] = ' C ' ; int j ; for ( j = i ; j < str . length - 1 ; j ++ ) str [ j ] = str [ j + 1 ] ; str [ j ] = ' ▁ ' ; } } return ; } public static void main ( String args [ ] ) { String st = " helloABworldABGfG " ; char str [ ] = st . toCharArray ( ) ; translate ( str ) ; System . out . println ( " The ▁ modified ▁ string ▁ is ▁ : " ) ; System . out . println ( str ) ; } }

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 final int ROW = 3 ; static final int COL = 5 ; static boolean isvalid ( int row , int col , int prevRow , int prevCol ) { return ( row >= 0 ) && ( row < ROW ) && ( col >= 0 ) && ( col < COL ) && ! ( row == prevRow && col == prevCol ) ; } static int rowNum [ ] = { - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 } ; static int colNum [ ] = { - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 } ; static void DFS ( char mat [ ] [ ] , int row , int col , int prevRow , int prevCol , char [ ] word , String path , int index , int n ) { if ( index > n mat [ row ] [ col ] != word [ index ] ) return ; path += ( word [ index ] ) + " ( " + String . valueOf ( row ) + " , ▁ " + String . valueOf ( col ) + " ) ▁ " ; if ( index == n ) { System . out . print ( path + "NEW_LINE"); return ; } for ( int k = 0 ; k < 8 ; ++ k ) if ( isvalid ( row + rowNum [ k ] , col + colNum [ k ] , prevRow , prevCol ) ) DFS ( mat , row + rowNum [ k ] , col + colNum [ k ] , row , col , word , path , index + 1 , n ) ; } static void findWords ( char mat [ ] [ ] , char [ ] word , int n ) { for ( int i = 0 ; i < ROW ; ++ i ) for ( int j = 0 ; j < COL ; ++ j ) if ( mat [ i ] [ j ] == word [ 0 ] ) DFS ( mat , i , j , - 1 , - 1 , word , " " , 0 , n ) ; } public static void main ( String [ ] args ) { char mat [ ] [ ] = { { ' B ' , ' N ' , ' E ' , ' Y ' , ' S ' } , { ' H ' , ' E ' , ' D ' , ' E ' , ' S ' } , { ' S ' , ' G ' , ' N ' , ' D ' , ' E ' } } ; char [ ] word = " DES " . toCharArray ( ) ; findWords ( mat , word , word . length - 1 ) ; } }

Index/key variables: col, i, index, j, k, row
Accumulator variables: path
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; public class index { static int max = 0 ; static String ans1 = " " ; static void calculate ( String ans ) { int dp [ ] = new int [ 26 ] ; for ( int i = 0 ; i < ans . length ( ) ; ++ i ) { dp [ ans . charAt ( i ) - ' A ' ] ++ ; } for ( int i = 0 ; i < dp . length ; ++ i ) { if ( dp [ i ] % 2 == 1 ) { return ; } } if ( max < ans . length ( ) ) { max = ans . length ( ) ; ans1 = ans ; } } static void longestString ( List < String > arr , int index , String str ) { if ( index == arr . size ( ) ) { return ; } longestString ( arr , index + 1 , str ) ; str += arr . get ( index ) ; calculate ( str ) ; longestString ( arr , index + 1 , str ) ; } public static void main ( String [ ] args ) { ArrayList < String > A = new ArrayList < > ( ) ; A . add ( " ABAB " ) ; A . add ( " ABF " ) ; A . add ( " CDA " ) ; A . add ( " AD " ) ; A . add ( " CCC " ) ; longestString ( A , 0 , " " ) ; System . out . println ( ans1 + " ▁ " + ans1 . length ( ) ) ; } }

Index/key variables: i
Accumulator variables: str
Iterator variables: i
Class/struct names: index
Java program:
class GFG { public static String generateNumber ( String number ) { int temp = 0 , adding_number = 0 ; String result = " " ; int len = number . length ( ) ; for ( int i = len - 1 ; i >= 0 ; i -- ) { int digit = ( int ) number . charAt ( i ) - ( int ) '0' ; if ( temp % 2 == 0 ) { adding_number += 1 ; digit += adding_number ; if ( digit >= 10 ) { digit %= 9 ; if ( digit == 0 ) digit = 9 ; } } result = digit + result ; temp += 1 ; } return result ; } public static void main ( String args [ ] ) { String S = "1345" ; System . out . println ( generateNumber ( S ) ) ; } }

Accumulator variables: adding_number, digit, i, temp
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static int findK ( String s , char c ) { int n = s . length ( ) ; int diff ; int max = 0 ; int prev = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == c ) { diff = i - prev ; prev = i ; if ( diff > max ) { max = diff ; } } } if ( max == 0 ) return - 1 ; return max ; } public static void main ( String args [ ] ) { String S = " abdegb " ; char ch = ' b ' ; System . out . println ( findK ( S , ch ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countSubsequence ( String S , int N , int K ) { int C = 0 , C1 = 0 , C0 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) == '1' ) C1 ++ ; else if ( S . charAt ( i ) == '0' ) C0 ++ ; } int B1 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) == '1' ) B1 ++ ; else if ( S . charAt ( i ) == '0' ) C = C + ( C1 - B1 ) ; } int ans = C * K ; ans += ( C1 * C0 * ( ( ( K ) * ( K - 1 ) ) / 2 ) ) ; return ans ; } public static void main ( String [ ] args ) { String S = "230013110087" ; int K = 2 ; int N = S . length ( ) ; System . out . println ( countSubsequence ( S , N , K ) ) ; } }

Accumulator variables: B1, C0, C1, ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minSwaps ( String s ) { int ones = 0 , zeros = 0 ; int N = s . length ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == '1' ) ones ++ ; else zeros ++ ; } if ( ( N % 2 == 0 && ones != zeros ) || ( N % 2 == 1 && Math . abs ( ones - zeros ) != 1 ) ) { return - 1 ; } int ans_1 = 0 ; int j = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == '1' ) { ans_1 += Math . abs ( j - i ) ; j += 2 ; } } int ans_0 = 0 ; int k = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == '0' ) { ans_0 += Math . abs ( k - i ) ; k += 2 ; } } if ( N % 2 == 0 ) return Math . min ( ans_1 , ans_0 ) ; else { if ( ones > zeros ) return ans_1 ; else return ans_0 ; } } public static void main ( String [ ] args ) { String S = "110100" ; System . out . print ( minSwaps ( S ) ) ; } }

Accumulator variables: ans_0, ans_1, i, j, k, ones, zeros
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static ArrayList < String > TotalPossibleJumps ( int N ) { if ( ( N - 1 ) == 0 ) { ArrayList < String > newvec = new ArrayList < String > ( ) ; newvec . add ( " " ) ; return newvec ; } else { if ( N < 0 ) { ArrayList < String > newvec = new ArrayList < String > ( ) ; return newvec ; } } ArrayList < String > jump1 = TotalPossibleJumps ( N - 1 ) ; ArrayList < String > jump2 = TotalPossibleJumps ( N - 2 ) ; ArrayList < String > totaljumps = new ArrayList < String > ( ) ; for ( String s : jump1 ) { totaljumps . add ( "1" + s ) ; } for ( String s : jump2 ) { totaljumps . add ( "2" + s ) ; } return totaljumps ; } public static void main ( String [ ] args ) { int N = 3 ; ArrayList < String > Ans = TotalPossibleJumps ( N ) ; for ( String it : Ans ) System . out . println ( it ) ; } }

Iterator variables: it, s
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static String findString ( String arr [ ] , int N ) { String ans = " " ; for ( int i = 0 ; i < N ; i ++ ) { ans += arr [ i ] . charAt ( i ) == '0' ? '1' : '0' ; } return ans ; } public static void main ( String [ ] args ) { String arr [ ] = { "111" , "011" , "001" } ; int N = arr . length ; System . out . println ( findString ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static void commonSubstring ( String s ) { int n = s . length ( ) ; int i = 0 ; int j = n - 1 ; String ans = " " ; while ( j >= 0 ) { if ( s . charAt ( i ) == s . charAt ( j ) ) { ans += s . charAt ( i ) ; i ++ ; j -- ; } else { break ; } } if ( ans . length ( ) == 0 ) System . out . println ( " False " ) ; else { System . out . println ( " True ▁ " ) ; System . out . println ( ans ) ; } } public static void main ( String [ ] args ) { String S = " abca " ; commonSubstring ( S ) ; } }

Accumulator variables: ans, i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static void findMinimumSubsequence ( String S ) { boolean flag = false ; StringBuilder dummy = new StringBuilder ( ) ; for ( int j = 0 ; j < S . length ( ) ; j ++ ) { if ( S . charAt ( j ) != '2' && S . charAt ( j ) != '3' && S . charAt ( j ) != '5' && S . charAt ( j ) != '7' ) { System . out . println ( 1 ) ; flag = true ; break ; } } if ( ! flag ) { loop : for ( int j = 0 ; j < S . length ( ) - 1 ; j ++ ) { for ( int j1 = j + 1 ; j1 < S . length ( ) ; j1 ++ ) { dummy = new StringBuilder ( Character . toString ( S . charAt ( j ) ) ) ; dummy . append ( S . charAt ( j1 ) ) ; if ( ! dummy . toString ( ) . equals ( "23" ) && ! dummy . toString ( ) . equals ( "37" ) && ! dummy . toString ( ) . equals ( "53" ) && ! dummy . toString ( ) . equals ( "73" ) ) { System . out . println ( 2 ) ; flag = true ; break loop ; } } } } if ( ! flag ) { if ( S . length ( ) >= 3 ) { System . out . println ( 3 ) ; } else { System . out . println ( - 1 ) ; } } } public static void main ( String [ ] args ) { String S = "237" ; findMinimumSubsequence ( S ) ; } }

Accumulator variables: j, j1
Iterator variables: j, j1
Boolean variables: flag
Class/struct names: GFG