dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . Arrays ; class GFG { static double countSubSequence ( int [ ] arr , int n ) { int maximum = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; int minimum = Arrays . stream ( arr ) . min ( ) . getAsInt ( ) ; if ( maximum == minimum ) return Math . pow ( 2 , n ) - 1 ; int i = count ( arr , maximum ) ; int j = count ( arr , minimum ) ; double res = ( Math . pow ( 2 , i ) - 1 ) * ( Math . pow ( 2 , j ) - 1 ) * Math . pow ( 2 , n - i - j ) ; return res ; } static int count ( int [ ] arr , int value ) { int sum = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) if ( arr [ i ] == value ) sum ++ ; return sum ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 } ; int n = arr . length ; System . out . println ( countSubSequence ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int transformSubsequence ( int n , int m , int [ ] A , int [ ] B ) { if ( B . length == 0 ) return n ; int [ ] [ ] dp = new int [ n + 1 ] [ m + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < m + 1 ; j ++ ) { if ( i == 0 j == 0 ) dp [ i ] [ j ] = 0 ; else if ( A [ i - 1 ] == B [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } return n - dp [ n ] [ m ] ; } public static void main ( String [ ] args ) { int N = 5 ; int M = 6 ; int [ ] A = { 1 , 2 , 3 , 4 , 5 } ; int [ ] B = { 2 , 5 , 6 , 4 , 9 , 12 } ; System . out . print ( transformSubsequence ( N , M , A , B ) ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int checkForPerfectSquare ( int [ ] arr , int i , int j ) { int mid , sum = 0 ; for ( int m = i ; m <= j ; m ++ ) { sum += arr [ m ] ; } int low = 0 , high = sum / 2 ; while ( low <= high ) { mid = low + ( high - low ) / 2 ; if ( mid * mid == sum ) { return mid ; } else if ( mid * mid > sum ) { high = mid - 1 ; } else { low = mid + 1 ; } } return - 1 ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 19 , 33 , 48 , 90 , 100 } ; int L = 1 , R = 3 ; System . out . print ( checkForPerfectSquare ( arr , L , R ) ) ; } }

Index/key variables: m
Accumulator variables: m, sum
Iterator variables: m
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int calcSubarray ( int A [ ] , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { boolean flag = true ; int comm_diff = A [ i + 1 ] - A [ i ] ; for ( int k = i ; k < j ; k ++ ) { if ( A [ k + 1 ] - A [ k ] == comm_diff ) { continue ; } else { flag = false ; break ; } } if ( flag ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int [ ] A = { 8 , 7 , 4 , 1 , 0 } ; int N = A . length ; System . out . print ( calcSubarray ( A , N ) ) ; } }

Index/key variables: i, k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . Math ; import java . util . * ; public class GFG { public static int maxSumSubarray ( int [ ] arr ) { int i = 0 , j = 1 ; HashSet < Integer > set = new HashSet < Integer > ( ) ; set . add ( arr [ 0 ] ) ; int sum = arr [ 0 ] ; int maxsum = sum ; while ( i < arr . length - 1 && j < arr . length ) { if ( ! set . contains ( arr [ j ] ) ) { sum = sum + arr [ j ] ; maxsum = Math . max ( sum , maxsum ) ; set . add ( arr [ j ++ ] ) ; } else { sum -= arr [ i ] ; set . remove ( arr [ i ++ ] ) ; } } return maxsum ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 1 , 2 , 3 , 1 , 5 } ; int ans = maxSumSubarray ( arr ) ; System . out . println ( ans ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int count_numbers ( int L , int R ) { int ans = 0 ; for ( int n = L ; n <= R ; n ++ ) { int no_of_bits = ( int ) ( Math . log ( n ) + 1 ) ; int no_of_set_bits = Integer . bitCount ( n ) ; if ( no_of_bits - no_of_set_bits == 1 ) { ans ++ ; } } return ans ; } public static void main ( String [ ] args ) { int L = 4 , R = 9 ; System . out . print ( count_numbers ( L , R ) ) ; } }

Accumulator variables: ans, n
Iterator variables: n
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int count_numbers ( int L , int R ) { int ans = 0 ; int LogR = ( int ) ( Math . log ( R ) + 1 ) ; for ( int zero_bit = 0 ; zero_bit < LogR ; zero_bit ++ ) { int cur = 0 ; for ( int j = 0 ; j < zero_bit ; j ++ ) { cur |= ( 1L << j ) ; } for ( int j = zero_bit + 1 ; j < LogR ; j ++ ) { cur |= ( 1L << j ) ; if ( cur >= L && cur <= R ) { ans ++ ; } } } return ans ; } public static void main ( String [ ] args ) { int L = 4 , R = 9 ; System . out . print ( count_numbers ( L , R ) ) ; } }

Accumulator variables: ans, cur, j, zero_bit
Iterator variables: j, zero_bit
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findSum ( String s ) { int sum = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { for ( int j = i + 1 ; j < s . length ( ) ; j ++ ) { if ( s . charAt ( i ) == s . charAt ( j ) ) { sum += ( j - i ) ; } } } return sum ; } public static void main ( String [ ] args ) { String s = " ttt " ; System . out . print ( findSum ( s ) + "NEW_LINE"); } }

Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countElements ( int [ ] a , int n ) { int [ ] cnt = new int [ n + 1 ] ; int ans = 0 ; for ( int k : a ) { ++ cnt [ k ] ; } for ( int l = 0 ; l < n ; ++ l ) { int sum = 0 ; for ( int r = l ; r < n ; ++ r ) { sum += a [ r ] ; if ( l == r ) continue ; if ( sum <= n ) { ans += cnt [ sum ] ; cnt [ sum ] = 0 ; } } } return ans ; } public static void main ( String [ ] args ) { int [ ] a = { 1 , 1 , 1 , 1 , 1 } ; System . out . println ( countElements ( a , a . length ) ) ; } }

Index/key variables: k, r, sum
Accumulator variables: ans, sum
Iterator variables: k, l, r
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxGCD ( int n ) { int maxHcf = Integer . MIN_VALUE ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { maxHcf = Math . max ( maxHcf , __gcd ( i , j ) ) ; } } return maxHcf ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( maxGCD ( n ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int maxGCD ( int n ) { return ( n / 2 ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( maxGCD ( n ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String removeOddIndexCharacters ( String s ) { String new_string = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i % 2 == 1 ) continue ; new_string += s . charAt ( i ) ; } return new_string ; } public static void main ( String [ ] args ) { String str = " abcdef " ; str = removeOddIndexCharacters ( str ) ; System . out . print ( str ) ; } }

Accumulator variables: i, new_string
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int longestGP ( int A [ ] , int N ) { if ( N < 2 ) return N ; int length = 1 , common_ratio = 1 ; int maxlength = 1 ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i + 1 ] % A [ i ] == 0 ) { if ( A [ i + 1 ] / A [ i ] == common_ratio ) { length = length + 1 ; maxlength = Math . max ( maxlength , length ) ; } else { common_ratio = A [ i + 1 ] / A [ i ] ; length = 2 ; } } else { maxlength = Math . max ( maxlength , length ) ; length = 1 ; } } maxlength = Math . max ( maxlength , length ) ; return maxlength ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 4 , 7 , 14 , 28 , 56 , 89 } ; int N = arr . length ; System . out . println ( longestGP ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int uncrossedLines ( int [ ] a , int [ ] b , int n , int m ) { int [ ] [ ] dp = new int [ n + 1 ] [ m + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= m ; j ++ ) { if ( i == 0 j == 0 ) dp [ i ] [ j ] = 0 ; else if ( a [ i - 1 ] == b [ j - 1 ] ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } return dp [ n ] [ m ] ; } public static void main ( String [ ] args ) { int A [ ] = { 3 , 9 , 2 } ; int B [ ] = { 3 , 2 , 9 } ; int N = A . length ; int M = B . length ; System . out . print ( uncrossedLines ( A , B , N , M ) ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int minFlips ( int mat [ ] [ ] , String s ) { int N = mat . length ; int M = mat [ 0 ] . length ; int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] != s . charAt ( i + j ) - '0' ) { count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 1 , 0 , 1 } , { 0 , 1 , 1 } , { 0 , 0 , 0 } } ; String s = "10001" ; System . out . print ( minFlips ( mat , s ) ) ; } }

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 void lcmpair ( int l , int r ) { int x , y ; x = l ; y = 2 * l ; if ( y > r ) { System . out . print ( "-1NEW_LINE"); } else { System . out . print ( " X ▁ = ▁ " + x + " ▁ Y ▁ = ▁ " + y + "NEW_LINE"); } } public static void main ( String [ ] args ) { int l = 13 , r = 69 ; lcmpair ( l , r ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int revNum ( int N ) { int x = 0 ; while ( N != 0 ) { x = x * 10 + N % 10 ; N = N / 10 ; } return x ; } static int ctNonPalin ( int arr [ ] , int N ) { int Res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int x = revNum ( arr [ i ] ) ; if ( x == arr [ i ] ) { continue ; } else { if ( arr [ i ] % 10 == x % 10 ) Res += 1 ; } } return Res ; } public static void main ( String [ ] args ) { int arr [ ] = { 121 , 134 , 2342 , 4514 } ; int N = arr . length ; System . out . println ( ctNonPalin ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: Res, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minlt ( int [ ] arr , int target , int n ) { int [ ] [ ] dp = new int [ arr . length + 1 ] [ target + 1 ] ; for ( int [ ] row : dp ) Arrays . fill ( row , - 1 ) ; for ( int i = 0 ; i < arr . length + 1 ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( int j = 0 ; j < target + 1 ; j ++ ) dp [ 0 ] [ j ] = Integer . MAX_VALUE ; for ( int i = 1 ; i <= arr . length ; i ++ ) { for ( int j = 1 ; j <= target ; j ++ ) { if ( arr [ i - 1 ] > j ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; } else { dp [ i ] [ j ] = Math . min ( dp [ i - 1 ] [ j ] , ( dp [ i ] [ j - arr [ i - 1 ] ] ) != Integer . MAX_VALUE ? ( dp [ i ] [ j - arr [ i - 1 ] ] + 1 ) : Integer . MAX_VALUE ) ; } } } if ( dp [ arr . length ] [ target ] == Integer . MAX_VALUE ) { return - 1 ; } else { return dp [ arr . length ] [ target ] ; } } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 5 , 4 , 1 } ; int target = 11 ; int n = arr . length ; System . out . print ( minlt ( arr , target , n ) ) ; } }

Index/key variables: i, j, target
Accumulator variables: i, j
Iterator variables: i, j, row
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minServerLoads ( int n , int [ ] servers ) { int totalLoad = 0 ; for ( int i = 0 ; i < servers . length ; i ++ ) totalLoad += servers [ i ] ; int requiredLoad = totalLoad / 2 ; int dp [ ] [ ] = new int [ n + 1 ] [ requiredLoad + 1 ] ; for ( int i = 1 ; i < n + 1 ; i ++ ) { for ( int j = 1 ; j < requiredLoad + 1 ; j ++ ) { if ( servers [ i - 1 ] > j ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; else dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , servers [ i - 1 ] + dp [ i - 1 ] [ j - servers [ i - 1 ] ] ) ; } } return totalLoad - 2 * dp [ n ] [ requiredLoad ] ; } public static void main ( String [ ] args ) { int N = 5 ; int servers [ ] = { 1 , 2 , 3 , 4 , 5 } ; System . out . print ( minServerLoads ( N , servers ) ) ; } }

Index/key variables: i, j, n, requiredLoad
Accumulator variables: i, j, totalLoad
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxLenSub ( int arr [ ] , int N ) { int Pos = 0 ; int Neg = 0 ; int res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 0 ) { Pos = Neg = 0 ; } else if ( arr [ i ] > 0 ) { Pos += 1 ; if ( Neg != 0 ) { Neg += 1 ; } res = Math . max ( res , Pos ) ; } else { Pos = Pos + Neg ; Neg = Pos - Neg ; Neg = Pos - Neg ; Neg += 1 ; if ( Pos != 0 ) { Pos += 1 ; } res = Math . max ( res , Pos ) ; } } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , - 2 , - 3 , 0 , 1 } ; int N = arr . length ; System . out . print ( maxLenSub ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: Neg, Pos, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxLength ( String [ ] arr ) { int len = Integer . MIN_VALUE ; int N = arr . length ; for ( int i = 0 ; i < N ; i ++ ) { int l = arr [ i ] . length ( ) ; if ( len < l ) { len = l ; } } return len ; } static void maxStrings ( String [ ] arr , int len ) { int N = arr . length ; Vector < String > ans = new Vector < String > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( len == arr [ i ] . length ( ) ) { ans . add ( arr [ i ] ) ; } } for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { System . out . print ( ans . get ( i ) + " ▁ " ) ; } } static void printStrings ( String [ ] arr ) { int max = maxLength ( arr ) ; maxStrings ( arr , max ) ; } public static void main ( String [ ] args ) { String [ ] arr = { " aba " , " aa " , " ad " , " vcd " , " aba " } ; printStrings ( arr ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int min_flips ( String str , int k ) { if ( str . length ( ) == 0 ) return 0 ; int ans = 0 ; int cnt_zeros = 0 ; for ( char ch : str . toCharArray ( ) ) { if ( ch == '0' ) { ++ cnt_zeros ; } else { cnt_zeros = 0 ; } if ( cnt_zeros == k ) { ++ ans ; cnt_zeros = 0 ; } } return ans ; } public static void main ( String [ ] args ) { String str = "11100000011" ; int k = 3 ; System . out . print ( min_flips ( str , k ) ) ; } }

Iterator variables: ch
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static List < List < Integer > > maxSubArray ( int [ ] arr , int K ) { List < List < Integer > > solution = new ArrayList < > ( ) ; int multi = 1 ; int start = 0 ; if ( arr . length <= 1 K < 0 ) { return new ArrayList < > ( ) ; } for ( int i = 0 ; i < arr . length ; i ++ ) { multi = multi * arr [ i ] ; while ( multi > K ) { multi = multi / arr [ start ] ; start ++ ; } List < Integer > list = new ArrayList < > ( ) ; for ( int j = i ; j >= start ; j -- ) { list . add ( 0 , arr [ j ] ) ; solution . add ( new ArrayList < > ( list ) ) ; } } return solution ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 7 , 1 , 4 } ; int K = 7 ; System . out . println ( maxSubArray ( arr , K ) ) ; } }

Index/key variables: i, j, start
Accumulator variables: i, j, start
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static double solve ( int [ ] [ ] D , int N , int X , int Y ) { ArrayList < Double > T = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int x = D [ i ] [ 0 ] ; int y = D [ i ] [ 1 ] ; double speed = D [ i ] [ 2 ] ; double time = ( ( x * x - X * X ) + ( y * y - Y * Y ) ) / ( speed * speed ) ; T . add ( time ) ; } Collections . sort ( T ) ; int i = 0 ; int total = 0 ; while ( i < ( T . size ( ) - 1 ) ) { int count = 1 ; while ( ( i < ( T . size ( ) - 1 ) ) && ( Double . compare ( T . get ( i ) , T . get ( i + 1 ) ) == 0 ) ) { count += 1 ; i += 1 ; } total += ( count * ( count - 1 ) ) / 2 ; i += 1 ; } return total ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int N = 5 ; int [ ] [ ] D = { { 5 , 12 , 1 } , { 16 , 63 , 5 } , { - 10 , 24 , 2 } , { 7 , 24 , 2 } , { - 24 , 7 , 2 } } ; int X = 0 , Y = 0 ; System . out . println ( solve ( D , N , X , Y ) ) ; } }

Index/key variables: i
Accumulator variables: count, i, total
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int getMaxLength ( int arr [ ] , int N ) { int res = 2 ; int dist = 2 ; int curradj = ( arr [ 1 ] - arr [ 0 ] ) ; int prevadj = ( arr [ 1 ] - arr [ 0 ] ) ; for ( int i = 2 ; i < N ; i ++ ) { curradj = arr [ i ] - arr [ i - 1 ] ; if ( curradj == prevadj ) { dist ++ ; } else { prevadj = curradj ; res = Math . max ( res , dist ) ; dist = 2 ; } } res = Math . max ( res , dist ) ; return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 7 , 4 , 6 , 8 , 10 , 11 } ; int N = arr . length ; System . out . print ( getMaxLength ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: dist, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int minSteps ( String str , int N ) { int smaller , cost = 0 ; int f [ ] = new int [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { int curr_ele = str . charAt ( i ) - ' a ' ; smaller = 0 ; for ( int j = 0 ; j <= curr_ele ; j ++ ) { if ( f [ j ] != 0 ) smaller += f [ j ] ; } if ( smaller == 0 ) cost += ( i + 1 ) ; else cost += ( i - smaller + 1 ) ; f [ str . charAt ( i ) - ' a ' ] ++ ; } return cost ; } public static void main ( String [ ] args ) { String str = " abcab " ; int N = str . length ( ) ; System . out . println ( minSteps ( str , N ) ) ; } }

Index/key variables: j
Accumulator variables: cost, i, j, smaller
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int [ ] findSubarrays ( int [ ] a ) { int n = a . length ; int [ ] freq = new int [ n + 1 ] ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { if ( count == 0 ) continue ; else { int value = count ; for ( int j = 1 ; j <= count ; j ++ ) { freq [ j ] += value ; value -- ; } count = 0 ; } } else count ++ ; } if ( count > 0 ) { int value = count ; for ( int j = 1 ; j <= count ; j ++ ) { freq [ j ] += value ; value -- ; } } return freq ; } static void countRectangles ( int [ ] a , int [ ] b , int K ) { int n = a . length ; int m = b . length ; int [ ] subA = findSubarrays ( a ) ; int [ ] subB = findSubarrays ( b ) ; int total = 0 ; for ( int i = 1 ; i < subA . length ; i ++ ) { if ( K % i == 0 && ( K / i ) <= m ) { total = total + subA [ i ] * subB [ K / i ] ; } } System . out . print ( total ) ; } public static void main ( String [ ] args ) { int [ ] a = { 0 , 0 , 1 , 1 } ; int [ ] b = { 1 , 0 , 1 } ; int K = 2 ; countRectangles ( a , b , K ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j, value
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printRes ( Vector < Integer > res ) { Enumeration enu = res . elements ( ) ; while ( enu . hasMoreElements ( ) ) { System . out . print ( enu . nextElement ( ) + " ▁ " ) ; } } static void printLBS ( int arr [ ] , int N ) { int lis [ ] = new int [ N ] ; int lds [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { lis [ i ] = lds [ i ] = 1 ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] < arr [ i ] ) { if ( lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; } } } for ( int i = N - 1 ; i >= 0 ; i -- ) { for ( int j = N - 1 ; j > i ; j -- ) { if ( arr [ j ] < arr [ i ] ) { if ( lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ; } } } int MaxVal = arr [ 0 ] , inx = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( MaxVal < lis [ i ] + lds [ i ] - 1 ) { MaxVal = lis [ i ] + lds [ i ] - 1 ; inx = i ; } } int ct1 = lis [ inx ] ; Vector < Integer > res = new Vector < Integer > ( ) ; for ( int i = inx ; i >= 0 && ct1 > 0 ; i -- ) { if ( lis [ i ] == ct1 ) { res . add ( arr [ i ] ) ; ct1 -- ; } } Collections . reverse ( res ) ; int ct2 = lds [ inx ] - 1 ; for ( int i = inx ; i < N && ct2 > 0 ; i ++ ) { if ( lds [ i ] == ct2 ) { res . add ( arr [ i ] ) ; ct2 -- ; } } printRes ( res ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 80 , 60 , 30 , 40 , 20 , 10 } ; int N = arr . length ; printLBS ( arr , N ) ; } }

Index/key variables: N, i, inx, j
Accumulator variables: ct1, ct2, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { public static boolean possible ( int T , int arr [ ] , int n , int d ) { int partition = 1 ; int total = 0 ; for ( int i = 0 ; i < n ; i ++ ) { total = total + arr [ i ] ; if ( total > T ) { partition = partition + 1 ; total = arr [ i ] ; if ( partition > d ) { return false ; } } } return true ; } public static void calcT ( int n , int d , int arr [ ] ) { int mx = - 1 , sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mx = Math . max ( mx , arr [ i ] ) ; sum = sum + arr [ i ] ; } int lb = mx ; int ub = sum ; while ( lb < ub ) { int T_mid = lb + ( ub - lb ) / 2 ; if ( possible ( T_mid , arr , n , d ) == true ) { ub = T_mid ; } else { lb = T_mid + 1 ; } } System . out . println ( lb ) ; } public static void main ( String args [ ] ) { int d = 2 ; int arr [ ] = { 1 , 1 , 1 , 1 , 1 } ; int n = arr . length ; calcT ( n , d , arr ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minReqSubstring ( String s , int n ) { char ongoing = ' N ' ; int count = 0 , l = s . length ( ) ; for ( int i = 1 ; i < l ; i ++ ) { if ( ongoing == ' N ' ) { if ( s . charAt ( i ) < s . charAt ( i - 1 ) ) { ongoing = ' D ' ; } else if ( s . charAt ( i ) == s . charAt ( i - 1 ) ) { ongoing = ' N ' ; } else { ongoing = ' I ' ; } } else if ( ongoing == ' I ' ) { if ( s . charAt ( i ) > s . charAt ( i - 1 ) ) { ongoing = ' I ' ; } else if ( s . charAt ( i ) == s . charAt ( i - 1 ) ) { ongoing = ' I ' ; } else { ongoing = ' N ' ; count += 1 ; } } else { if ( s . charAt ( i ) < s . charAt ( i - 1 ) ) { ongoing = ' D ' ; } else if ( s . charAt ( i ) == s . charAt ( i - 1 ) ) { ongoing = ' D ' ; } else { ongoing = ' N ' ; count += 1 ; } } } return count + 1 ; } public static void main ( String [ ] args ) { String S = " aeccdhba " ; int n = S . length ( ) ; System . out . print ( minReqSubstring ( S , n ) ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minimum_required_operations ( int arr [ ] , int n , int k ) { int answer = 0 ; long mod = 1000000007 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] + arr [ i + 1 ] > k ) { if ( arr [ i ] > k ) { answer += ( arr [ i ] - k ) ; arr [ i ] = k ; } answer += ( arr [ i ] + arr [ i + 1 ] ) - k ; arr [ i + 1 ] = ( k - arr [ i ] ) ; answer %= mod ; } } return answer ; } public static void main ( String [ ] args ) { int a [ ] = { 9 , 50 , 4 , 14 , 42 , 89 } ; int k = 10 ; int n = a . length ; System . out . print ( minimum_required_operations ( a , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: answer, i
Iterator variables: i
Class/struct names: GFG