dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static void printSubsInDelimeters ( String str ) { Stack < Integer > dels = new Stack < Integer > ( ) ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == ' [ ' ) { dels . add ( i ) ; } else if ( str . charAt ( i ) == ' ] ' && ! dels . isEmpty ( ) ) { int pos = dels . peek ( ) ; dels . pop ( ) ; int len = i - 1 - pos ; String ans = str . substring ( pos + 1 , pos + 1 + len ) ; System . out . print ( ans + "NEW_LINE"); } } } public static void main ( String [ ] args ) { String str = " [ This ▁ is ▁ first ] ▁ ignored ▁ text ▁ [ This ▁ is ▁ second ] " ; printSubsInDelimeters ( str ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void printDiagonalTraversal ( int [ ] [ ] nums ) { int m = nums . length ; Queue < pair > q = new LinkedList < > ( ) ; q . add ( new pair ( 0 , 0 ) ) ; while ( ! q . isEmpty ( ) ) { pair p = q . peek ( ) ; q . remove ( ) ; System . out . print ( nums [ p . first ] [ p . second ] + " ▁ " ) ; if ( p . second == 0 && p . first + 1 < m ) { q . add ( new pair ( p . first + 1 , p . second ) ) ; } if ( p . second + 1 < nums [ p . first ] . length ) q . add ( new pair ( p . first , p . second + 1 ) ) ; } } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; printDiagonalTraversal ( arr ) ; } }

Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static Vector < Integer > restore ( int arr [ ] , int N ) { Vector < Integer > result = new Vector < > ( ) ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) && mp . get ( arr [ i ] ) == 0 ) { result . add ( arr [ i ] ) ; if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } else mp . put ( arr [ i ] , 0 ) ; } return result ; } static void print_result ( Vector < Integer > result ) { for ( int i = 0 ; i < result . size ( ) ; i ++ ) System . out . print ( result . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 13 , 1 , 24 , 13 , 24 , 2 , 2 } ; int N = arr . length ; print_result ( restore ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Vector < Integer > restore ( int arr [ ] , int N ) { Vector < Integer > result = new Vector < Integer > ( ) ; int count1 = 1 ; HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { s . add ( arr [ i ] ) ; if ( s . size ( ) == count1 ) { result . add ( arr [ i ] ) ; count1 ++ ; } } return result ; } static void print_result ( Vector < Integer > result ) { for ( int i = 0 ; i < result . size ( ) ; i ++ ) System . out . print ( result . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 13 , 1 , 24 , 13 , 24 , 2 , 2 } ; int N = arr . length ; print_result ( restore ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: count1, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int sum ( int n ) { return n * ( n - 1 ) / 2 ; } static void BSpattern ( int N ) { int Val = 0 , Pthree = 0 , cnt = 0 , initial = - 1 ; String s = " * * " ; for ( int i = 0 ; i < N ; i ++ ) { cnt = 0 ; if ( i > 0 ) { System . out . print ( s ) ; s += " * * " ; } for ( int j = i ; j < N ; j ++ ) { if ( i > 0 ) { cnt ++ ; } System . out . print ( ++ Val ) ; System . out . print ( "0" ) ; } if ( i == 0 ) { int Sumbeforelast = sum ( Val ) * 2 ; Pthree = Val + Sumbeforelast + 1 ; initial = Pthree ; } initial = initial - cnt ; Pthree = initial ; for ( int k = i ; k < N ; k ++ ) { System . out . print ( Pthree ++ ) ; if ( k != N - 1 ) { System . out . print ( "0" ) ; } } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int N = 5 ; BSpattern ( N ) ; } }

Accumulator variables: Pthree, cnt, i, j, k, s
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
class GFG { static boolean checkprefix ( int A , int B ) { String s1 = String . valueOf ( A ) ; String s2 = String . valueOf ( B ) ; int n1 = s1 . length ( ) ; int n2 = s2 . length ( ) ; if ( n1 < n2 ) { return false ; } for ( int i = 0 ; i < n2 ; i ++ ) { if ( s1 . charAt ( i ) != s2 . charAt ( 1 ) ) { return false ; } } return true ; } public static void main ( String [ ] args ) { int A = 12345 , B = 12 ; boolean result = checkprefix ( A , B ) ; if ( ! result ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void possibleToReach ( int x , int y , int z ) { if ( z < Math . abs ( x ) + Math . abs ( y ) || ( z - Math . abs ( x ) - Math . abs ( y ) ) % 2 == 1 ) { System . out . print ( " Not ▁ Possible " + "NEW_LINE"); } else System . out . print ( " Possible " + "NEW_LINE"); } public static void main ( String [ ] args ) { int x = 5 , y = 5 ; int z = 11 ; possibleToReach ( x , y , z ) ; } }

Class/struct names: GFG
Java program:
class GFG { static int nCycle ( int N ) { return ( N ) * ( N - 1 ) + 1 ; } public static void main ( String [ ] args ) { int N = 4 ; System . out . println ( nCycle ( N ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int a [ ] = new int [ 65 ] ; static int Count ( int i ) { if ( i == 0 ) return 1 ; else if ( i < 0 ) return 0 ; if ( a [ i ] == 0 ) { a [ i ] = ( i + 1 ) + 2 * Count ( i - 1 ) ; return a [ i ] ; } else return a [ i ] ; } static int solve ( int n ) { int i , sum = 0 ; while ( n > 0 ) { i = ( int ) ( Math . log ( n ) / Math . log ( 2 ) ) ; n = n - ( int ) Math . pow ( 2 , i ) ; sum = sum + ( i + 1 ) + Count ( i - 1 ) ; } return sum ; } public static void main ( String [ ] args ) { int n = 7 ; System . out . println ( solve ( n ) ) ; } }

Index/key variables: i
Class/struct names: GFG
Java program:
import javafx . util . Pair ; public class Main { public static Pair < Integer , Integer > count_ht ( char s , int N ) { Pair < Integer , Integer > p = new Pair < Integer , Integer > ( 0 , 0 ) ; if ( s == ' H ' ) { p = new Pair < Integer , Integer > ( ( int ) Math . floor ( N / 2.0 ) , ( int ) Math . ceil ( N / 2.0 ) ) ; } else if ( s == ' T ' ) { p = new Pair < Integer , Integer > ( ( int ) Math . ceil ( N / 2.0 ) , ( int ) Math . floor ( N / 2.0 ) ) ; } return p ; } public static void main ( String [ ] args ) { char C = ' H ' ; int N = 5 ; Pair < Integer , Integer > p = count_ht ( C , N ) ; System . out . println ( " Head ▁ = ▁ " + p . getKey ( ) ) ; System . out . println ( " Tail ▁ = ▁ " + p . getValue ( ) ) ; } }

Class/struct names: Main
Java program:
import java . util . * ; class GFG { static String findPalindrome ( String C ) { String S = C ; S = reverse ( S ) ; C = C + " & " + S ; int n = C . length ( ) ; int [ ] longestPalindrome = new int [ n ] ; longestPalindrome [ 0 ] = 0 ; int len = 0 ; int i = 1 ; while ( i < n ) { if ( C . charAt ( i ) == C . charAt ( len ) ) { len ++ ; longestPalindrome [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = longestPalindrome [ len - 1 ] ; } else { longestPalindrome [ i ] = 0 ; i ++ ; } } } String ans = C . substring ( 0 , longestPalindrome [ n - 1 ] ) ; return ans ; } static String findAns ( String s ) { String A = " " ; String B = " " ; String F = " " ; int i = 0 ; int j = s . length ( ) - 1 ; int len = s . length ( ) ; while ( i < j && s . charAt ( i ) == s . charAt ( j ) ) { i = i + 1 ; j = j - 1 ; } if ( i > 0 ) { A = s . substring ( 0 , i ) ; B = s . substring ( len - i , len ) ; } if ( len > 2 * i ) { String C = s . substring ( i , ( s . length ( ) - 2 * i ) + i ) ; String D = findPalindrome ( C ) ; C = reverse ( C ) ; String E = findPalindrome ( C ) ; if ( D . length ( ) > E . length ( ) ) { F = D ; } else { F = E ; } } String answer = A + F + B ; return answer ; } static String reverse ( String input ) { char [ ] a = input . toCharArray ( ) ; int l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . valueOf ( a ) ; } public static void main ( String [ ] args ) { String str = " abcdefghiedcba " ; System . out . print ( findAns ( str ) + "NEW_LINE"); } }

Index/key variables: i, l, n, r
Accumulator variables: i, l, len, r
Iterator variables: l
Class/struct names: GFG
Java program:
class GFG { static int nthTerm ( int N ) { int nth = 0 ; if ( N % 2 == 1 ) nth = ( N * N ) + 1 ; else nth = ( N * N ) - 1 ; return nth ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . print ( nthTerm ( N ) + "NEW_LINE"); } }

Class/struct names: GFG
Java program:
class GFG { static int nthTerm ( int N ) { int nth = 0 , first_term = 12 ; nth = ( int ) ( ( first_term * ( Math . pow ( 2 , N - 1 ) ) ) + 11 * ( ( Math . pow ( 2 , N - 1 ) ) - 1 ) ) ; return nth ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . print ( nthTerm ( N ) + "NEW_LINE"); } }

Class/struct names: GFG
Java program:
class GFG { static int nthTerm ( int N ) { int nth = 0 , first_term = 4 ; int pi = 1 , po = 1 ; int n = N ; while ( n > 1 ) { pi *= n - 1 ; n -- ; po *= 2 ; } nth = ( first_term * pi ) / po ; return nth ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . print ( nthTerm ( N ) + "NEW_LINE"); } }

Accumulator variables: n, pi, po
Class/struct names: GFG
Java program:
class GFG { static int finalNum ( int arr [ ] , int n ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { result = __gcd ( result , arr [ i ] ) ; } return result ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 9 , 6 , 36 } ; int n = arr . length ; System . out . print ( finalNum ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static boolean isVowel ( char ch ) { switch ( ch ) { case ' a ' : case ' e ' : case ' i ' : case ' o ' : case ' u ' : return true ; } return false ; } static boolean isSatisfied ( char [ ] str , int n ) { for ( int i = 1 ; i < n ; i ++ ) { if ( ! isVowel ( str [ i ] ) && ! isVowel ( str [ i - 1 ] ) ) { return false ; } } for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( isVowel ( str [ i ] ) && ! isVowel ( str [ i - 1 ] ) && ! isVowel ( str [ i + 1 ] ) ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String str = " acaba " ; int n = str . length ( ) ; if ( isSatisfied ( str . toCharArray ( ) , n ) ) 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:
class GfG { static int LengthlongestPrefixSuffix ( String s ) { int n = s . length ( ) ; int lps [ ] = new int [ n ] ; lps [ 0 ] = 0 ; int len = 0 ; int i = 1 ; while ( i < n ) { if ( s . charAt ( i ) == s . charAt ( len ) ) { len ++ ; lps [ i ] = len ; i ++ ; } else { if ( len != 0 ) { len = lps [ len - 1 ] ; } else { lps [ i ] = 0 ; i ++ ; } } } int res = lps [ n - 1 ] ; return ( res > n / 2 ) ? n / 2 : res ; } static String longestPrefixSuffix ( String s ) { int len = LengthlongestPrefixSuffix ( s ) ; String prefix = " " ; for ( int i = 0 ; i < len ; i ++ ) prefix += s . charAt ( i ) ; return prefix ; } public static void main ( String [ ] args ) { String s = " abcab " ; String ans = longestPrefixSuffix ( s ) ; if ( ans == " " ) System . out . println ( " - 1" ) ; else System . out . println ( ans ) ; } }

Index/key variables: i, n
Accumulator variables: i, len, prefix
Iterator variables: i
Class/struct names: GfG
Java program:
import java . util . * ; class GFG { static int no_of_characters ( int M ) { int k = 1 ; while ( true ) { if ( ( int ) Math . pow ( 2 , k + 1 ) - 2 < M ) k ++ ; else break ; } return k ; } static void print_string ( int M ) { int k , num , N ; k = no_of_characters ( M ) ; N = M - ( ( int ) Math . pow ( 2 , k ) - 2 ) ; while ( k > 0 ) { num = ( int ) Math . pow ( 2 , k - 1 ) ; if ( num >= N ) System . out . print ( " A " ) ; else { System . out . print ( " B " ) ; N -= num ; } k -- ; } System . out . println ( ) ; } public static void main ( String args [ ] ) { int M ; M = 30 ; print_string ( M ) ; M = 55 ; print_string ( M ) ; M = 100 ; print_string ( M ) ; } }

Accumulator variables: N, k
Class/struct names: GFG
Java program:
class GFG { static String updateString ( String S , String A , String B ) { int l = A . length ( ) ; for ( int i = 0 ; i + l <= S . length ( ) ; i ++ ) { String curr = S . substring ( i , i + l ) ; if ( curr . equals ( A ) ) { String new_string = S . substring ( 0 , i ) + B + S . substring ( i + l , S . length ( ) ) ; S = new_string ; i += l - 1 ; } else { String new_string = S . substring ( 0 , i ) + A + S . substring ( i + l , S . length ( ) ) ; S = new_string ; i += l - 1 ; } } return S ; } public static void main ( String [ ] args ) { String S = " aab " ; String A = " aa " ; String B = " bb " ; System . out . println ( updateString ( S , A , B ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void printPattern ( int n , int m ) { if ( m > 2 * ( n + 1 ) m < n - 1 ) { System . out . print ( " - 1" ) ; } else if ( Math . abs ( n - m ) <= 1 ) { while ( n > 0 && m > 0 ) { System . out . print ( "01" ) ; n -- ; m -- ; } if ( n != 0 ) { System . out . print ( "0" ) ; } if ( m != 0 ) { System . out . print ( "1" ) ; } } else { while ( m - n > 1 && n > 0 ) { System . out . print ( "110" ) ; m = m - 2 ; n = n - 1 ; } while ( n > 0 ) { System . out . print ( "10" ) ; n -- ; m -- ; } while ( m > 0 ) { System . out . print ( "1" ) ; m -- ; } } } public static void main ( String [ ] args ) { int n = 4 , m = 8 ; printPattern ( n , m ) ; } }

Accumulator variables: m, n
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countDecreasing ( int A [ ] , int n ) { int len = 1 ; for ( int i = 0 ; i < n - 1 ; ++ i ) { if ( A [ i + 1 ] < A [ i ] ) len ++ ; else { cnt += ( ( ( len - 1 ) * len ) / 2 ) ; len = 1 ; } } if ( len > 1 ) cnt += ( ( ( len - 1 ) * len ) / 2 ) ; return cnt ; } public static void main ( String [ ] args ) { int A [ ] = { 100 , 3 , 1 , 13 } ; int n = A . length ; System . out . println ( countDecreasing ( A , n ) ) ; } }

Index/key variables: i
Accumulator variables: cnt, len
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int minimumChar ( String S1 , String S2 ) { int n = S1 . length ( ) ; int m = S2 . length ( ) ; int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < m - n + 1 ; i ++ ) { int minRemovedChar = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( S1 . charAt ( j ) != S2 . charAt ( i + j ) ) { minRemovedChar ++ ; } } ans = Math . min ( minRemovedChar , ans ) ; } return ans ; } public static void main ( String [ ] args ) { String S1 = " abc " ; String S2 = " paxzk " ; System . out . println ( minimumChar ( S1 , S2 ) ) ; } }

Accumulator variables: i, j, minRemovedChar
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int countFreq ( String pat , String txt ) { int M = pat . length ( ) ; int N = txt . length ( ) ; int res = 0 ; for ( int i = 0 ; i <= N - M ; i ++ ) { int j ; for ( j = 0 ; j < M ; j ++ ) { if ( txt . charAt ( i + j ) != pat . charAt ( j ) ) { break ; } } if ( j == M ) { res ++ ; j = 0 ; } } return res ; } static public void main ( String [ ] args ) { String txt = " dhimanman " ; String pat = " man " ; System . out . println ( countFreq ( pat , txt ) ) ; } }

Accumulator variables: i, j, res
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { public static int findMissingDigit ( String a , String b , String c ) { int w = 1 ; int a_mod_11 = 0 ; for ( int i = a . length ( ) - 1 ; i >= 0 ; i -- ) { a_mod_11 = ( a_mod_11 + w * ( a . charAt ( i ) - '0' ) ) % 11 ; w = w * - 1 ; } int b_mod_11 = 0 ; w = 1 ; for ( int i = b . length ( ) - 1 ; i >= 0 ; i -- ) { b_mod_11 = ( b_mod_11 + w * ( b . charAt ( i ) - '0' ) ) % 11 ; w = w * - 1 ; } int c_mod_11 = 0 ; boolean xSignIsPositive = true ; w = 1 ; for ( int i = c . length ( ) - 1 ; i >= 0 ; i -- ) { if ( c . charAt ( i ) == ' x ' ) { xSignIsPositive = ( w == 1 ) ; } else { c_mod_11 = ( c_mod_11 + w * ( c . charAt ( i ) - '0' ) ) % 11 ; } w = w * - 1 ; } int x = ( ( a_mod_11 * b_mod_11 ) - c_mod_11 ) % 11 ; if ( ! xSignIsPositive ) { x = - x ; } return ( x % 11 + 11 ) % 11 ; } public static void main ( String args [ ] ) { String A = "123456789" ; String B = "987654321" ; String C = "12193263111x635269" ; System . out . println ( findMissingDigit ( A , B , C ) ) ; } }

Accumulator variables: i
Iterator variables: i
Boolean variables: xSignIsPositive
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static void findIfPossible ( int N , String str ) { int countG = 0 , countF = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( str . charAt ( i ) == ' G ' ) countG ++ ; else countF ++ ; } if ( 2 * countF != countG ) { System . out . println ( " No " ) ; } else { int id = 0 ; boolean flag = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( str . charAt ( i ) == ' G ' ) { countG -- ; id ++ ; } else { countF -- ; id -- ; } if ( id < 0 ) { flag = false ; break ; } if ( countG < countF ) { flag = false ; break ; } } if ( flag ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } public static void main ( String [ ] args ) { int n = 6 ; String str = " GFGFGG " ; findIfPossible ( n , str ) ; } }

Accumulator variables: countF, countG, i, id
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { public static void isPossible ( String str1 , String str2 ) { int arr [ ] = new int [ 256 ] ; Arrays . fill ( arr , 0 ) ; int l1 = str1 . length ( ) ; int l2 = str2 . length ( ) ; int i , j ; boolean possible = true ; for ( i = 0 ; i < l1 ; i ++ ) { arr [ str1 . charAt ( i ) ] = 1 ; } for ( i = 0 ; i < l2 ; i ++ ) { if ( str2 . charAt ( i ) != ' ▁ ' ) { if ( arr [ str2 . charAt ( i ) ] == 1 ) continue ; else { possible = false ; break ; } } } if ( possible ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } public static void main ( String args [ ] ) { String str1 = " we ▁ all ▁ love ▁ geeksforgeeks " ; String str2 = " we ▁ all ▁ love ▁ geeks " ; isPossible ( str1 , str2 ) ; } }

Accumulator variables: i
Iterator variables: i
Boolean variables: possible
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int find_Min_Inversion ( int n , char [ ] s1 , char [ ] s2 ) { int count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( s1 [ i ] != s2 [ i ] ) { if ( s1 [ i ] == '1' ) { s1 [ i ] = '0' ; } else { s1 [ i ] = '1' ; } if ( s1 [ i + 1 ] == '1' ) { s1 [ i + 1 ] = '0' ; } else { s1 [ i + 1 ] = '1' ; } count ++ ; } } if ( String . copyValueOf ( s1 ) . equals ( String . copyValueOf ( s2 ) ) ) { return count ; } return - 1 ; } public static void main ( String [ ] args ) { int n = 4 ; String s1 = "0101" ; String s2 = "1111" ; System . out . print ( find_Min_Inversion ( n , s1 . toCharArray ( ) , s2 . toCharArray ( ) ) + "NEW_LINE"); } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; import java . util . Arrays ; class GFG { static int findSubsequence ( String S , char ch ) { int N = S . length ( ) ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) == ch ) { ans ++ ; ch ++ ; } } return ans ; } static int findMaxSubsequence ( String S ) { int ans = 0 ; for ( char ch = ' a ' ; ch <= ' z ' ; ch ++ ) { ans = Math . max ( ans , findSubsequence ( S , ch ) ) ; } return ans ; } public static void main ( String [ ] args ) { String S = " abcabefghijk " ; System . out . print ( findMaxSubsequence ( S ) ) ; } }

Accumulator variables: ans, ch, i
Iterator variables: ch, i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void minOpsToEmptyString ( String s ) { int ans = Integer . MIN_VALUE ; int cn0 = 0 ; int cn1 = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '0' ) { if ( cn1 > 0 ) cn1 -- ; cn0 ++ ; } else { if ( cn0 > 0 ) cn0 -- ; cn1 ++ ; } ans = Math . max ( ans , Math . max ( cn0 , cn1 ) ) ; } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { String S = "010101" ; minOpsToEmptyString ( S ) ; } }

Accumulator variables: cn0, cn1, i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG_JAVA { static int shortestString ( String S , int N ) { int st = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( st > 0 && S . charAt ( i ) == '1' ) { st -- ; } else { st ++ ; } } return st ; } public static void main ( String [ ] args ) { String S = "1010" ; int N = S . length ( ) ; System . out . println ( shortestString ( S , N ) ) ; } }

Accumulator variables: i, st
Iterator variables: i
Class/struct names: GFG_JAVA
Java program:
class GFG { static int findLength ( String str , int n ) { int pre [ ] = new int [ n ] ; int post [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { pre [ i ] = 0 ; post [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { if ( i != 0 ) { pre [ i ] += pre [ i - 1 ] ; } if ( str . charAt ( i ) == '1' ) { pre [ i ] += 1 ; } } for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( i != n - 1 ) post [ i ] += post [ i + 1 ] ; if ( str . charAt ( i ) == '0' ) post [ i ] += 1 ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans = Math . max ( ans , pre [ i ] + post [ i ] ) ; } return ans ; } public static void main ( String [ ] args ) { String S = "0101110110100001011" ; System . out . println ( findLength ( S , S . length ( ) ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . HashMap ; class GFG { static int countSubstring ( String S , int N ) { HashMap < Integer , Integer > prevSum = new HashMap < > ( ) ; int res = 0 ; int currentSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) >= ' A ' && S . charAt ( i ) <= ' Z ' ) { currentSum ++ ; } else currentSum -- ; if ( currentSum == 0 ) res ++ ; if ( prevSum . containsKey ( currentSum ) ) { res += prevSum . get ( currentSum ) ; } prevSum . put ( currentSum , prevSum . getOrDefault ( currentSum , 0 ) + 1 ) ; } return res ; } public static void main ( String [ ] args ) { String S = " gEEk " ; System . out . println ( countSubstring ( S , S . length ( ) ) ) ; } }

Accumulator variables: currentSum, i, res
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static int subString ( String s , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int len = i + 1 ; len <= n ; len ++ ) { String test_str = s . substring ( i , len ) ; HashMap < Character , Integer > res = new HashMap < > ( ) ; for ( char keys : test_str . toCharArray ( ) ) { res . put ( keys , res . getOrDefault ( keys , 0 ) + 1 ) ; } int flag = 0 ; for ( char keys : res . keySet ( ) ) { if ( res . get ( keys ) % 2 != 0 ) { flag = 1 ; break ; } } if ( flag == 0 ) count += 1 ; } } return count ; } public static void main ( String [ ] args ) { String S = " abbaa " ; int N = S . length ( ) ; System . out . println ( subString ( S , N ) ) ; } }

Accumulator variables: count, i, len
Iterator variables: i, keys, len
Class/struct names: GFG