dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static void findMaxLengthSequence ( int N , int [ ] arr ) { int rightmost_element = - 1 ; int i = 0 ; int j = N - 1 ; Vector < Integer > sequence = new Vector < Integer > ( ) ; while ( i <= j ) { if ( arr [ i ] > arr [ j ] ) { if ( arr [ j ] > rightmost_element ) { sequence . add ( arr [ j ] ) ; rightmost_element = arr [ j ] ; j -- ; } else if ( arr [ i ] > rightmost_element ) { sequence . add ( arr [ i ] ) ; rightmost_element = arr [ i ] ; i ++ ; } else break ; } else if ( arr [ i ] < arr [ j ] ) { if ( arr [ i ] > rightmost_element ) { sequence . add ( arr [ i ] ) ; rightmost_element = arr [ i ] ; i ++ ; } else if ( arr [ j ] > rightmost_element ) { sequence . add ( arr [ j ] ) ; rightmost_element = arr [ j ] ; j -- ; } else break ; } else if ( arr [ i ] == arr [ j ] ) { if ( i == j ) { if ( arr [ i ] > rightmost_element ) { sequence . add ( arr [ i ] ) ; rightmost_element = arr [ i ] ; i ++ ; } break ; } else { sequence . add ( arr [ i ] ) ; int k = i + 1 ; Vector < Integer > max_left = new Vector < Integer > ( ) ; while ( k < j && arr [ k ] > arr [ k - 1 ] ) { max_left . add ( arr [ k ] ) ; k ++ ; } int l = j - 1 ; Vector < Integer > max_right = new Vector < Integer > ( ) ; while ( l > i && arr [ l ] > arr [ l + 1 ] ) { max_right . add ( arr [ l ] ) ; l -- ; } if ( max_left . size ( ) > max_right . size ( ) ) for ( int element : max_left ) sequence . add ( element ) ; else for ( int element : max_right ) sequence . add ( element ) ; break ; } } } for ( int element : sequence ) System . out . print ( element + " ▁ " ) ; } public static void main ( String [ ] args ) { int N = 4 ; int [ ] arr = { 1 , 3 , 2 , 1 } ; findMaxLengthSequence ( N , arr ) ; } }

Index/key variables: i, j, k, l
Accumulator variables: i, j, k, l
Iterator variables: element
Class/struct names: GFG
Java program:
import java . util . * ; class TreeNode { public int val ; public List < TreeNode > children ; public TreeNode ( int v ) { val = v ; children = new ArrayList < TreeNode > ( ) ; } } class GFG { static double ans = 0.0 ; public static double [ ] MaxAverage ( TreeNode root ) { if ( root . children != null && root . children . size ( ) == 0 ) { ans = Math . max ( ans , root . val ) ; return new double [ ] { root . val , 1 } ; } double [ ] childResult = new double [ 2 ] ; for ( TreeNode child : root . children ) { double [ ] childTotal = MaxAverage ( child ) ; childResult [ 0 ] = childResult [ 0 ] + childTotal [ 0 ] ; childResult [ 1 ] = childResult [ 1 ] + childTotal [ 1 ] ; } double sum = childResult [ 0 ] + root . val ; double count = childResult [ 1 ] + 1 ; ans = Math . max ( ans , sum / count ) ; return new double [ ] { sum , count } ; } public static void main ( String [ ] args ) { TreeNode root = new TreeNode ( 20 ) ; TreeNode left = new TreeNode ( 12 ) ; TreeNode right = new TreeNode ( 18 ) ; root . children . add ( left ) ; root . children . add ( right ) ; left . children . add ( new TreeNode ( 11 ) ) ; left . children . add ( new TreeNode ( 3 ) ) ; right . children . add ( new TreeNode ( 15 ) ) ; right . children . add ( new TreeNode ( 8 ) ) ; MaxAverage ( root ) ; System . out . println ( ans ) ; } }

Iterator variables: child
Class/struct names: GFG, TreeNode
Java program:
class GFG { public static void canTransformStrings ( String A , String B ) { int n1 = A . length ( ) ; int n2 = B . length ( ) ; int count1A = 0 , count1B = 0 ; int odd1A = 0 , odd1B = 0 ; int even1A = 0 , even1B = 0 ; for ( int i = 0 ; i < n1 ; i ++ ) { if ( A . charAt ( i ) == '1' ) count1A ++ ; else { if ( ( count1A & 1 ) == 1 ) odd1A ++ ; else even1A ++ ; } } for ( int i = 0 ; i < n2 ; i ++ ) { if ( B . charAt ( i ) == '1' ) count1B ++ ; else { if ( ( count1B & 1 ) == 1 ) odd1B ++ ; else even1B ++ ; } } if ( count1A == count1B && odd1A == odd1B && even1A == even1B ) { System . out . print ( " Yes " ) ; } else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { String A = "10011" , B = "11100" ; canTransformStrings ( A , B ) ; } }

Accumulator variables: count1A, count1B, even1A, even1B, i, odd1A, odd1B
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void printAnswer ( int answer [ ] , int N ) { for ( int i = 1 ; i <= N ; i ++ ) { System . out . print ( answer [ i ] + " ▁ " ) ; } } static void updateAnswerArray ( int answer [ ] , int N ) { int i = 0 ; while ( answer [ i ] == - 1 ) i ++ ; int minimum = answer [ i ] ; while ( i <= N ) { if ( answer [ i ] == - 1 ) answer [ i ] = minimum ; else answer [ i ] = Math . min ( minimum , answer [ i ] ) ; minimum = Math . min ( minimum , answer [ i ] ) ; i ++ ; } } static void lengthOfSubarray ( ArrayList < ArrayList < Integer > > indices , Set < Integer > st , int N ) { int [ ] answer = new int [ N + 1 ] ; Arrays . fill ( answer , - 1 ) ; Iterator itr = st . iterator ( ) ; while ( itr . hasNext ( ) ) { int start = - 1 ; int gap = - 1 ; int t = ( int ) itr . next ( ) ; indices . get ( t ) . add ( N ) ; for ( int i = 0 ; i < indices . get ( t ) . size ( ) ; i ++ ) { gap = Math . max ( gap , indices . get ( t ) . get ( i ) - start ) ; start = indices . get ( t ) . get ( i ) ; } if ( answer [ gap ] == - 1 ) answer [ gap ] = t ; } updateAnswerArray ( answer , N ) ; printAnswer ( answer , N ) ; } static void smallestPresentNumber ( int arr [ ] , int N ) { ArrayList < ArrayList < Integer > > indices = new ArrayList < > ( ) ; for ( int i = 0 ; i <= N ; i ++ ) indices . add ( new ArrayList < Integer > ( ) ) ; Set < Integer > elements = new HashSet < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { indices . get ( arr [ i ] ) . add ( i ) ; elements . add ( arr [ i ] ) ; } lengthOfSubarray ( indices , elements , N ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 5 , 3 , 2 , 3 , 1 , 3 , 2 , 7 } ; int N = arr . length ; smallestPresentNumber ( arr , N ) ; } }

Index/key variables: gap, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int smallestLeft ( int arr [ ] , int total , int sum , int i , int [ ] [ ] dp ) { if ( i == 0 ) { return Math . abs ( total - 2 * sum ) ; } if ( dp [ i ] [ sum ] != - 1 ) return dp [ i ] [ sum ] ; int X = smallestLeft ( arr , total , sum + arr [ i - 1 ] , i - 1 , dp ) ; int Y = smallestLeft ( arr , total , sum , i - 1 , dp ) ; return dp [ i ] [ sum ] = Math . min ( X , Y ) ; } static void UtilSmallestElement ( int arr [ ] , int N ) { int total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { total += arr [ i ] ; } int [ ] [ ] dp = new int [ N + 1 ] [ total ] ; for ( int [ ] k : dp ) Arrays . fill ( k , - 1 ) ; System . out . println ( smallestLeft ( arr , total , 0 , N , dp ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 7 , 4 , 1 , 8 , 1 } ; int N = arr . length ; UtilSmallestElement ( arr , N ) ; } }

Index/key variables: i, sum, total
Accumulator variables: i, total
Iterator variables: i, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int SmallestElementLeft ( int arr [ ] , int N ) { int totalSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { totalSum += arr [ i ] ; } int req = totalSum / 2 ; boolean [ ] dp = new boolean [ req + 1 ] ; Arrays . fill ( dp , false ) ; dp [ 0 ] = true ; int reach = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = req ; j - arr [ i ] >= 0 ; j -- ) { dp [ j ] = dp [ j ] || dp [ j - arr [ i ] ] ; if ( dp [ j ] ) { reach = Math . max ( reach , j ) ; } } } return totalSum - ( 2 * reach ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 2 } ; int N = arr . length ; System . out . print ( SmallestElementLeft ( arr , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, totalSum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int min_Operations ( String str1 , String str2 ) { int N = str1 . length ( ) ; char [ ] str = str1 . toCharArray ( ) ; int cntOp = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( str [ i ] == str2 . charAt ( i ) ) { continue ; } int ptr = i ; while ( ptr < N && str [ ptr ] != str2 . charAt ( ptr ) ) { str [ ptr ] = str2 . charAt ( ptr ) ; ptr += 2 ; } cntOp ++ ; } return cntOp ; } public static void main ( String [ ] args ) { String str1 = " abcdef " ; String str2 = " ffffff " ; System . out . println ( min_Operations ( str1 , str2 ) ) ; } }

Index/key variables: i, ptr
Accumulator variables: cntOp, i, ptr
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isComposite ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; return false ; } static boolean isPerfectSquare ( int x ) { int s = ( int ) Math . sqrt ( x ) ; return ( s * s == x ) ; } static boolean isFibonacci ( int n ) { return isPerfectSquare ( 5 * n * n + 4 ) || isPerfectSquare ( 5 * n * n - 4 ) ; } static void ifgcdFibonacci ( int a [ ] , int n , int k ) { Vector < Integer > compositeset = new Vector < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( isComposite ( a [ i ] ) && a [ i ] % k == 0 ) { compositeset . add ( a [ i ] ) ; } } int gcd = compositeset . get ( 0 ) ; for ( int i = 1 ; i < compositeset . size ( ) ; i ++ ) { gcd = __gcd ( gcd , compositeset . get ( i ) ) ; if ( gcd == 1 ) { break ; } } if ( isFibonacci ( gcd ) ) { System . out . print ( " Yes " ) ; return ; } System . out . print ( " No " ) ; return ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 34 , 2 , 4 , 8 , 5 , 7 , 11 } ; int n = arr . length ; int k = 2 ; ifgcdFibonacci ( arr , n , k ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int find_longest_subarray ( int [ ] A , int N , int K ) { int MaxLen = 0 ; int Len = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( K % A [ i ] == 0 ) { Len ++ ; MaxLen = Math . max ( MaxLen , Len ) ; } else { Len = 0 ; } } return MaxLen ; } public static void main ( String [ ] args ) { int [ ] A = { 2 , 8 , 3 , 10 , 6 , 7 , 4 , 9 } ; int N = A . length ; int K = 60 ; System . out . println ( find_longest_subarray ( A , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: Len, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Vector < Integer > exit = new Vector < > ( ) ; static int minTime ( int meeting [ ] [ ] , int n , int [ ] entrance , int m , int p ) { int ans = Integer . MAX_VALUE ; Arrays . sort ( entrance ) ; Collections . sort ( exit ) ; for ( int i = 0 ; i < n ; i ++ ) { int u = meeting [ i ] [ 0 ] ; int v = meeting [ i ] [ 1 ] ; int it1 = upper_bound ( entrance , 0 , entrance . length , u ) ; int it2 = lowerBound ( exit , 0 , exit . size ( ) , v ) ; int start = it1 - 1 ; int end = it2 ; if ( start >= 0 && start < m && end >= 0 && end < p ) ans = Math . min ( ans , exit . get ( end ) - entrance [ start ] ) ; } return ans >= Integer . MAX_VALUE ? - 1 : ans ; } static int upper_bound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } static int lowerBound ( Vector < Integer > vec , int low , int high , int element ) { int [ ] array = new int [ vec . size ( ) ] ; int k = 0 ; for ( Integer val : vec ) { array [ k ] = val ; k ++ ; } while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( element > array [ middle ] ) { low = middle + 1 ; } else { high = middle ; } } return low ; } public static void main ( String [ ] args ) { int meeting [ ] [ ] = { { 15 , 19 } , { 5 , 10 } , { 7 , 25 } } ; int [ ] entrance = { 4 , 13 , 25 , 2 } ; exit . add ( 10 ) ; exit . add ( 25 ) ; int n = meeting . length ; int m = entrance . length ; int p = exit . size ( ) ; System . out . print ( minTime ( meeting , n , entrance , m , p ) + "NEW_LINE"); } }

Index/key variables: i, k, middle, start
Accumulator variables: i, k
Iterator variables: i, val
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void splitArray ( int a [ ] , int n , int k ) { Vector < Integer > first = new Vector < > ( ) ; Vector < Integer > second = new Vector < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] <= k / 2 ) first . add ( a [ i ] ) ; else second . add ( a [ i ] ) ; } for ( int i = 0 ; i < first . size ( ) ; i ++ ) { System . out . print ( first . get ( i ) + " ▁ " ) ; } System . out . println ( ) ; for ( int i = 0 ; i < second . size ( ) ; i ++ ) { System . out . print ( second . get ( i ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int k = 5 ; int a [ ] = { 0 , 1 , 3 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int n = a . length ; splitArray ( a , n , k ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int MAX = 1001 ; public static int [ ] sieve ( ) { int spf [ ] = new int [ MAX ] ; spf [ 0 ] = spf [ 1 ] = - 1 ; for ( int i = 2 ; i < MAX ; i ++ ) { spf [ i ] = i ; } for ( int i = 4 ; i < MAX ; i = i + 2 ) { spf [ i ] = 2 ; } for ( int i = 3 ; i * i < MAX ; i ++ ) { if ( spf [ i ] == i ) { for ( int j = i * i ; j < MAX ; j = j + i ) { if ( spf [ j ] == j ) { spf [ j ] = i ; } } } } return spf ; } public static int countFactors ( int spf [ ] , int num ) { int count = 0 ; while ( num > 1 ) { count ++ ; num = num / spf [ num ] ; } return count ; } public static int [ ] precalculateSum ( int spf [ ] ) { int sum [ ] = new int [ MAX ] ; sum [ 0 ] = 0 ; for ( int i = 1 ; i < MAX ; i ++ ) { int prime_factor = countFactors ( spf , i ) ; if ( spf [ prime_factor ] == prime_factor ) { sum [ i ] = sum [ i - 1 ] + 1 ; } else { sum [ i ] = sum [ i - 1 ] ; } } return sum ; } public static void main ( String [ ] args ) { int spf [ ] = sieve ( ) ; int sum [ ] = precalculateSum ( spf ) ; int Q [ ] [ ] = { { 4 , 8 } , { 30 , 32 } } ; for ( int i = 0 ; i < 2 ; i ++ ) { System . out . print ( ( sum [ Q [ i ] [ 1 ] ] - sum [ Q [ i ] [ 0 ] - 1 ] ) + " ▁ " ) ; } } }

Index/key variables: MAX, i, j, num, prime_factor
Accumulator variables: count, i
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int isPerfect ( int N ) { int sum = 1 ; for ( int i = 2 ; i < Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { if ( i == N / i ) { sum += i ; } else { sum += i + N / i ; } } } if ( sum == N && N != 1 ) return 1 ; return 0 ; } static int maxSum ( int arr [ ] , int N , int K ) { if ( N < K ) { System . out . print ( " Invalid " ) ; return - 1 ; } int res = 0 ; for ( int i = 0 ; i < K ; i ++ ) { res += arr [ i ] ; } int curr_sum = res ; for ( int i = K ; i < N ; i ++ ) { curr_sum += arr [ i ] - arr [ i - K ] ; res = Math . max ( res , curr_sum ) ; } return res ; } static int max_PerfectNumbers ( int arr [ ] , int N , int K ) { for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = isPerfect ( arr [ i ] ) == 1 ? 1 : 0 ; } return maxSum ( arr , N , K ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 28 , 2 , 3 , 6 , 496 , 99 , 8128 , 24 } ; int K = 4 ; int N = arr . length ; System . out . print ( max_PerfectNumbers ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: curr_sum, i, res, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void display ( int countLeftGreater [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( countLeftGreater [ i ] + " ▁ " ) ; } } static void countGreater ( int arr [ ] , int N ) { Set < Integer > St = new TreeSet < > ( ) ; int [ ] countLeftGreater = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { St . add ( arr [ i ] ) ; int it = 0 ; Iterator < Integer > iterator = St . iterator ( ) ; while ( iterator . hasNext ( ) ) { if ( arr [ i ] < iterator . next ( ) ) { break ; } it ++ ; } countLeftGreater [ i ] = Math . abs ( it - St . size ( ) ) ; } display ( countLeftGreater , N ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 1 , 2 , 3 , 0 , 11 , 4 } ; int N = arr . length ; countGreater ( arr , N ) ; } }

Index/key variables: N, i
Accumulator variables: i, it
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int minCost ( String A , String B ) { int n = A . length ( ) ; int i = 0 ; int maxlen = 0 ; while ( i < n ) { int length = 0 ; for ( int j = 0 ; j < n ; ++ j ) { if ( A . charAt ( i ) == B . charAt ( j ) ) { ++ i ; ++ length ; if ( i == n ) break ; } } maxlen = Math . max ( maxlen , length ) ; } return n - maxlen ; } public static void main ( String [ ] args ) { String A = " edacb " ; String B = " abcde " ; System . out . println ( minCost ( A , B ) ) ; } }

Iterator variables: j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int lexicographicRank ( char [ ] s ) { int n = s . length ; Vector < Integer > [ ] alphaIndex = new Vector [ 26 ] ; for ( int i = 0 ; i < alphaIndex . length ; i ++ ) alphaIndex [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < s . length ; i ++ ) { int x = s [ i ] - ' a ' ; alphaIndex [ x ] . add ( i ) ; } int rank = 0 ; for ( int i = 0 ; i < 26 && ' a ' + i < s [ 0 ] ; i ++ ) { if ( alphaIndex [ i ] . size ( ) > 0 ) { for ( int j = 0 ; j < alphaIndex [ i ] . size ( ) ; j ++ ) { rank = rank + ( n - alphaIndex [ i ] . get ( j ) ) ; } } } Vector < String > str = new Vector < String > ( ) ; for ( int i = 0 ; i < alphaIndex [ s [ 0 ] - ' a ' ] . size ( ) ; i ++ ) { String subString = " " ; int j = alphaIndex [ s [ 0 ] - ' a ' ] . get ( i ) ; for ( ; j < n ; j ++ ) { subString += ( s [ j ] ) ; str . add ( subString ) ; } } Collections . sort ( str ) ; for ( int i = 0 ; i < str . size ( ) ; i ++ ) { if ( ! str . get ( i ) . equals ( String . valueOf ( s ) ) ) { rank ++ ; } else { break ; } } return rank + 1 ; } public static void main ( String [ ] args ) { String str = " enren " ; System . out . print ( lexicographicRank ( str . toCharArray ( ) ) ) ; } }

Index/key variables: i, j, x
Accumulator variables: i, j, rank, subString
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int hIndex ( int [ ] citations , int n ) { int hindex = 0 ; int low = 0 , high = n - 1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( citations [ mid ] >= ( mid + 1 ) ) { low = mid + 1 ; hindex = mid + 1 ; } else { high = mid - 1 ; } } System . out . println ( hindex ) ; return hindex ; } public static void main ( String [ ] args ) { int n = 5 ; int [ ] citations = { 5 , 3 , 3 , 2 , 2 } ; hIndex ( citations , n ) ; } }

Index/key variables: mid
Class/struct names: GFG
Java program:
class GFG { static boolean checkEqual ( String arr [ ] , int N ) { int hash [ ] = new int [ 256 ] ; int M = arr [ 0 ] . length ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { hash [ arr [ i ] . charAt ( j ) ] ++ ; } } for ( int i = 0 ; i < 256 ; i ++ ) { if ( hash [ i ] % N != 0 ) { return false ; } } return true ; } public static void main ( String [ ] args ) { String arr [ ] = { " fdd " , " fhh " } ; int N = arr . length ; if ( checkEqual ( arr , N ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class solution { static int [ ] [ ] dp = new int [ 100 ] [ 100 ] ; static int maxweight ( int s , int e , HashMap < Integer , Integer > pre ) { if ( s == e ) return 0 ; if ( dp [ s ] [ e ] != - 1 ) return dp [ s ] [ e ] ; int ans = 0 ; for ( int i = s ; i < e ; i ++ ) { int left = pre . get ( i ) - pre . get ( s - 1 ) ; int right = pre . get ( e ) - pre . get ( i ) ; if ( left < right ) ans = Math . max ( ans , ( int ) ( left + maxweight ( s , i , pre ) ) ) ; if ( left == right ) ans = Math . max ( ans , Math . max ( left + maxweight ( s , i , pre ) , right + maxweight ( i + 1 , e , pre ) ) ) ; if ( left > right ) ans = Math . max ( ans , right + maxweight ( i + 1 , e , pre ) ) ; dp [ s ] [ e ] = ans ; } return dp [ s ] [ e ] ; } static void maxSum ( int arr [ ] , int n ) { HashMap < Integer , Integer > pre = new HashMap < Integer , Integer > ( ) ; pre . put ( - 1 , 0 ) ; pre . put ( 0 , arr [ 0 ] ) ; for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 100 ; j ++ ) dp [ i ] [ j ] = - 1 ; } for ( int i = 0 ; i < n ; i ++ ) pre . put ( i , pre . get ( i - 1 ) + arr [ i ] ) ; System . out . print ( ( maxweight ( 0 , n - 1 , pre ) ) ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 6 , 2 , 3 , 4 , 5 , 5 } ; maxSum ( arr , 6 ) ; } }

Index/key variables: e, i, j, s
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: solution
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static Vector < Integer > storeLeaf ( Node root , Vector < Integer > arr ) { if ( root == null ) return arr ; if ( root . left == null && root . right == null ) { arr . add ( root . data ) ; return arr ; } arr = storeLeaf ( root . left , arr ) ; arr = storeLeaf ( root . right , arr ) ; return arr ; } static void KSmallest ( Node root , int k ) { Vector < Integer > arr = new Vector < Integer > ( ) ; arr = storeLeaf ( root , arr ) ; Collections . sort ( arr ) ; for ( int i = 0 ; i < k ; i ++ ) { if ( i < arr . size ( ) ) { System . out . print ( arr . get ( i ) + " ▁ " ) ; } else { break ; } } } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 4 ) ; root . left . left . left = newNode ( 21 ) ; root . left . right = newNode ( 5 ) ; root . left . right . right = newNode ( 8 ) ; root . right = newNode ( 3 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . right . right . right = newNode ( 19 ) ; KSmallest ( root , 3 ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
Java program:
import java . util . * ; import java . lang . * ; class GFG { static boolean allCoprime ( int A [ ] , int n ) { boolean all_coprime = true ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( gcd ( A [ i ] , A [ j ] ) != 1 ) { all_coprime = false ; break ; } } } return all_coprime ; } static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int A [ ] = { 3 , 5 , 11 , 7 , 19 } ; int arr_size = A . length ; if ( allCoprime ( A , arr_size ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: all_coprime
Class/struct names: GFG
Java program:
class GFG { static int smallestNum ( int n ) { double power = log2 ( 10 ) ; return ( int ) Math . ceil ( ( n - 1 ) * power ) ; } static double log2 ( int N ) { return ( Math . log ( N ) / Math . log ( 2 ) ) ; } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( smallestNum ( n ) ) ; } }

Class/struct names: GFG