dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . util . * ; class GFG { static int lenghtOfLongestAP ( int A [ ] , int n ) { Map < Integer , Map < Integer , Integer > > dp = new HashMap < Integer , Map < Integer , Integer > > ( ) ; int res = 2 ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = i + 1 ; j < n ; ++ j ) { int d = A [ j ] - A [ i ] ; Map < Integer , Integer > temp ; if ( dp . containsKey ( d ) ) { temp = dp . get ( d ) ; if ( temp . containsKey ( i ) ) temp . put ( j , temp . get ( i ) + 1 ) ; else temp . put ( j , 2 ) ; } else { temp = new HashMap < Integer , Integer > ( ) ; temp . put ( j , 2 ) ; } dp . put ( d , temp ) ; res = Math . max ( res , temp . get ( j ) ) ; } } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 20 , 1 , 15 , 3 , 10 , 5 , 8 } ; int N = arr . length ; System . out . println ( lenghtOfLongestAP ( arr , N ) ) ; } }

Index/key variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int N = 100005 ; static void SieveOfEratosthenes ( boolean prime [ ] , int p_size ) { prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= p_size ; p ++ ) { if ( prime [ p ] ) { for ( int i = p * 2 ; i <= p_size ; i += p ) prime [ i ] = false ; } } } static int LISPrime ( int arr [ ] , int n ) { int [ ] lisp = new int [ n ] ; boolean [ ] prime = new boolean [ N + 1 ] ; for ( int i = 0 ; i < prime . length ; i ++ ) prime [ i ] = true ; SieveOfEratosthenes ( prime , N ) ; lisp [ 0 ] = prime [ arr [ 0 ] ] ? 1 : 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( ! prime [ arr [ i ] ] ) { lisp [ i ] = 0 ; continue ; } lisp [ i ] = 1 ; for ( int j = 0 ; j < i ; j ++ ) { if ( prime [ arr [ j ] ] && arr [ i ] > arr [ j ] && lisp [ i ] < lisp [ j ] + 1 ) { lisp [ i ] = lisp [ j ] + 1 ; } } } return Arrays . stream ( lisp ) . max ( ) . getAsInt ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 5 , 3 , 2 , 5 , 1 , 7 } ; int M = arr . length ; System . out . print ( LISPrime ( arr , M ) ) ; } }

Index/key variables: i, j, n, p
Accumulator variables: i, j, p
Iterator variables: i, j, p
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void checkSumOfNatural ( int n ) { int i = 1 ; boolean flag = false ; while ( i * ( i + 1 ) < n * 2 ) { int X = i * ( i + 1 ) ; int t = n * 2 - X ; int k = ( int ) Math . sqrt ( t ) ; if ( k * ( k + 1 ) == t ) { flag = true ; break ; } i += 1 ; } if ( flag ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } public static void main ( String [ ] args ) { int n = 25 ; checkSumOfNatural ( n ) ; } }

Accumulator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static long binomialCoeff ( int n , int k ) { long res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } static long catalan ( int n ) { long c = binomialCoeff ( 2 * n , n ) ; return c / ( n + 1 ) ; } static long findWays ( int n ) { if ( ( n & 1 ) == 1 ) return 0 ; return catalan ( n / 2 ) ; } static void countNonNPeriodic ( int N ) { System . out . println ( findWays ( 2 * N ) - findWays ( N ) ) ; } public static void main ( String [ ] args ) { int N = 4 ; countNonNPeriodic ( N ) ; } }

Accumulator variables: res
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void checkSameDiag ( int li [ ] [ ] , int x , int y , int m , int n ) { int I = 0 , J = 0 ; int P = 0 , Q = 0 ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( li [ i ] [ j ] == x ) { I = i ; J = j ; } if ( li [ i ] [ j ] == y ) { P = i ; Q = j ; } } } if ( P - Q == I - J P + Q == I + J ) { System . out . println ( " YES " ) ; } else System . out . println ( " NO " ) ; } public static void main ( String [ ] args ) { int m = 6 ; int n = 5 ; int [ ] [ ] li = { { 32 , 94 , 99 , 26 , 82 } , { 51 , 69 , 52 , 63 , 17 } , { 90 , 36 , 88 , 55 , 33 } , { 93 , 42 , 73 , 39 , 28 } , { 81 , 31 , 83 , 53 , 10 } , { 12 , 29 , 85 , 80 , 87 } } ; int x = 42 ; int y = 80 ; checkSameDiag ( li , x , y , m , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int isValid ( int n , int m , int k ) { int step2 = n - m ; int cnt = ( step2 * ( step2 + 1 ) ) / 2 ; if ( cnt - m == k ) return 0 ; if ( cnt - m > k ) return 1 ; return - 1 ; } static void countOfOperations ( int n , int k ) { int start = 0 , end = n ; boolean ok = true ; while ( start <= end ) { int mid = ( start + end ) / 2 ; int temp = isValid ( n , mid , k ) ; if ( temp == 0 ) { ok = false ; System . out . print ( mid ) ; break ; } else if ( temp == 1 ) { start = mid + 1 ; } else { end = mid - 1 ; } } if ( ok ) System . out . print ( " - 1" ) ; } public static void main ( String [ ] args ) { int N = 5 , K = 4 ; countOfOperations ( N , K ) ; } }

Boolean variables: ok
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static boolean nonLower ( String s ) { for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ! Character . isLowerCase ( s . charAt ( i ) ) ) { return true ; } } return false ; } public static void printCodes ( String output [ ] ) { for ( int i = 0 ; i < output . length ; i ++ ) { if ( nonLower ( output [ i ] ) ) continue ; System . out . println ( output [ i ] ) ; } } public static char getChar ( int n ) { return ( char ) ( n + 96 ) ; } public static String [ ] getCode ( String str ) { if ( str . length ( ) == 0 ) { String ans [ ] = { " " } ; return ans ; } String output1 [ ] = getCode ( str . substring ( 1 ) ) ; String output2 [ ] = new String [ 0 ] ; int firstDigit = ( str . charAt ( 0 ) - '0' ) ; int firstTwoDigit = 0 ; if ( str . length ( ) >= 2 ) { firstTwoDigit = ( str . charAt ( 0 ) - '0' ) * 10 + ( str . charAt ( 1 ) - '0' ) ; if ( firstTwoDigit >= 10 && firstTwoDigit <= 26 ) { output2 = getCode ( str . substring ( 2 ) ) ; } } String output [ ] = new String [ output1 . length + output2 . length ] ; int k = 0 ; for ( int i = 0 ; i < output1 . length ; i ++ ) { char ch = getChar ( firstDigit ) ; output [ i ] = ch + output1 [ i ] ; k ++ ; } for ( int i = 0 ; i < output2 . length ; i ++ ) { char ch = getChar ( firstTwoDigit ) ; output [ k ] = ch + output2 [ i ] ; k ++ ; } return output ; } public static void main ( String [ ] args ) { String input = "101" ; String output [ ] = getCode ( input ) ; printCodes ( output ) ; } }

Index/key variables: i, k
Accumulator variables: i, k
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int isprm ( int n ) { if ( n <= 1 ) return 0 ; if ( n <= 3 ) return 1 ; if ( n % 2 == 0 n % 3 == 0 ) return 0 ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) { if ( n % i == 0 || n % ( i + 2 ) == 0 ) return 0 ; } return 1 ; } static int countprime ( int n ) { int count = 0 ; Vector < Integer > primevector = new Vector < > ( ) ; for ( int i = 2 ; i <= n ; i ++ ) { if ( isprm ( i ) == 1 ) { primevector . add ( i ) ; } } int sum = primevector . elementAt ( 0 ) ; for ( int i = 1 ; i < primevector . size ( ) ; i ++ ) { sum += primevector . elementAt ( i ) ; if ( sum > n ) break ; if ( isprm ( sum ) == 1 ) { count ++ ; } } return count ; } public static void main ( String [ ] args ) { int N = 45 ; System . out . print ( countprime ( N ) ) ; } }

Accumulator variables: count, i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static class pair { int first , second ; } static boolean isPerfectSquare ( int n ) { double sr = Math . sqrt ( n ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } static void SubarrayHavingPerfectSquare ( int [ ] arr , int k ) { pair ans = new pair ( ) ; int sum = 0 , i ; for ( i = 0 ; i < k ; i ++ ) { sum += arr [ i ] ; } boolean found = false ; if ( isPerfectSquare ( sum ) ) { ans . first = 0 ; ans . second = i - 1 ; } else { for ( int j = i ; j < arr . length ; j ++ ) { sum = sum + arr [ j ] - arr [ j - k ] ; if ( isPerfectSquare ( sum ) ) { found = true ; ans . first = j - k + 1 ; ans . second = j ; } } for ( int k1 = ans . first ; k1 <= ans . second ; k1 ++ ) { System . out . print ( arr [ k1 ] + " ▁ " ) ; } } if ( found == false ) { System . out . print ( " - 1" ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 20 , 34 , 51 , 10 , 99 , 87 , 23 , 45 } ; int K = 3 ; SubarrayHavingPerfectSquare ( arr , K ) ; } }

Index/key variables: i, j, k1
Accumulator variables: i, j, k1, sum
Iterator variables: i, j, k1
Boolean variables: found
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static int TEN = 10 ; static void updateFreq ( int n , int freq [ ] ) { while ( n > 0 ) { int digit = n % TEN ; freq [ digit ] ++ ; n /= TEN ; } } static boolean areAnagrams ( int a , int b ) { int freqA [ ] = new int [ TEN ] ; int freqB [ ] = new int [ TEN ] ; updateFreq ( a , freqA ) ; updateFreq ( b , freqB ) ; for ( int i = 0 ; i < TEN ; i ++ ) { if ( freqA [ i ] != freqB [ i ] ) return false ; } return true ; } static boolean isPowerOf2 ( int N ) { for ( int i = 0 ; i < 32 ; i ++ ) { if ( areAnagrams ( 1 << i , N ) ) { System . out . print ( ( 1 << i ) ) ; return true ; } } return false ; } public static void main ( String [ ] args ) { int N = 46 ; if ( ! isPowerOf2 ( N ) ) { System . out . print ( " No " ) ; } } }

Index/key variables: TEN, digit, i
Accumulator variables: i, n
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int right_angled ( int n ) { int count = 0 ; for ( int z = 1 ; z <= n ; z ++ ) { for ( int y = 1 ; y <= z ; y ++ ) { for ( int x = 1 ; x <= y ; x ++ ) { if ( ( x * x ) + ( y * y ) == ( z * z ) ) { count ++ ; } } } } return count ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( right_angled ( n ) ) ; } }

Accumulator variables: count, x, y, z
Iterator variables: x, y, z
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void mirrorMatrix ( int mat1 [ ] [ ] , int mat2 [ ] [ ] , int N ) { int row = 0 ; int col = 0 ; boolean isMirrorImage = true ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = N - 1 ; j >= 0 ; j -- ) { if ( mat2 [ row ] [ col ] != mat1 [ i ] [ j ] ) { isMirrorImage = false ; } col ++ ; } col = 0 ; row ++ ; } if ( isMirrorImage ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { int N = 4 ; int mat1 [ ] [ ] = { { 1 , 2 , 3 , 4 } , { 0 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; int mat2 [ ] [ ] = { { 4 , 3 , 2 , 1 } , { 8 , 7 , 6 , 0 } , { 12 , 11 , 10 , 9 } , { 16 , 15 , 14 , 13 } } ; mirrorMatrix ( mat1 , mat2 , N ) ; } }

Index/key variables: col, i, j, row
Accumulator variables: col, i, j, row
Iterator variables: i, j
Boolean variables: isMirrorImage
Class/struct names: GFG
Java program:
import java . util . Vector ; class GFG { static int dfs ( int src , int dest , int [ ] vis , Vector < Integer > [ ] adj ) { vis [ src ] = 1 ; if ( src == dest ) { return 1 ; } for ( int u : adj [ src ] ) { if ( vis [ u ] == 0 ) { int temp = dfs ( u , dest , vis , adj ) ; if ( temp != 0 ) { return temp + 1 ; } } } return 0 ; } static int countNodes ( int V , int E , int src , int dest , int edges [ ] [ ] ) { Vector < Integer > [ ] adj = new Vector [ V + 1 ] ; for ( int i = 0 ; i < adj . length ; i ++ ) adj [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < E ; i ++ ) { adj [ edges [ i ] [ 0 ] ] . add ( edges [ i ] [ 1 ] ) ; adj [ edges [ i ] [ 1 ] ] . add ( edges [ i ] [ 0 ] ) ; } int vis [ ] = new int [ V + 1 ] ; int count = dfs ( src , dest , vis , adj ) ; return count - 2 ; } public static void main ( String [ ] args ) { int V = 8 , E = 7 ; int src = 5 , dest = 2 ; int edges [ ] [ ] = { { 1 , 4 } , { 4 , 5 } , { 4 , 2 } , { 2 , 6 } , { 6 , 3 } , { 2 , 7 } , { 3 , 8 } } ; System . out . print ( countNodes ( V , E , src , dest , edges ) ) ; } }

Index/key variables: i, src, u
Accumulator variables: i
Iterator variables: i, u
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static long GCD ( long a , long b ) { if ( a == 0 ) return b ; return GCD ( b % a , a ) ; } static long LCM ( long a , long b ) { return ( a * b ) / GCD ( a , b ) ; } static void checkPairwiseCoPrime ( int A [ ] , int n ) { long prod = 1 ; long lcm = 1 ; for ( int i = 0 ; i < n ; i ++ ) { prod *= A [ i ] ; lcm = LCM ( A [ i ] , lcm ) ; } if ( prod == lcm ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 3 , 5 } ; int n = A . length ; checkPairwiseCoPrime ( A , n ) ; } }

Index/key variables: i
Accumulator variables: i, prod
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int maxDiffSubsets ( int [ ] arr ) { int totalSum = 0 ; boolean pos = false , neg = false ; int min = Integer . MAX_VALUE ; for ( int i = 0 ; i < arr . length ; i ++ ) { totalSum += Math . abs ( arr [ i ] ) ; if ( arr [ i ] > 0 ) pos = true ; if ( arr [ i ] < 0 ) neg = true ; if ( arr [ i ] < min ) min = arr [ i ] ; } if ( pos && neg ) return totalSum ; else return totalSum - 2 * min ; } public static void main ( String [ ] args ) { int [ ] S = { 1 , 2 , 1 } ; int N = S . length ; if ( N < 2 ) System . out . println ( " Not ▁ Possible " ) ; else System . out . println ( maxDiffSubsets ( S ) ) ; } }

Index/key variables: i
Accumulator variables: i, totalSum
Iterator variables: i
Boolean variables: neg, pos
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int minDiffSubArray ( int arr [ ] , int n ) { int [ ] prefix_sum = new int [ n ] ; prefix_sum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) prefix_sum [ i ] = prefix_sum [ i - 1 ] + arr [ i ] ; int [ ] suffix_sum = new int [ n ] ; suffix_sum [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) suffix_sum [ i ] = suffix_sum [ i + 1 ] + arr [ i ] ; int minDiff = Integer . MAX_VALUE ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int diff = Math . abs ( prefix_sum [ i ] - suffix_sum [ i + 1 ] ) ; if ( diff < minDiff ) minDiff = diff ; } return minDiff ; } public static void main ( String [ ] args ) { int [ ] arr = { 7 , 9 , 5 , 10 } ; int n = arr . length ; System . out . println ( minDiffSubArray ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void dailyTemperatures ( int [ ] T ) { int n = T . length ; int [ ] daysOfWait = new int [ n ] ; Arrays . fill ( daysOfWait , - 1 ) ; Stack < Integer > s = new Stack < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( ! s . isEmpty ( ) && T [ s . peek ( ) ] < T [ i ] ) { daysOfWait [ s . peek ( ) ] = i - s . peek ( ) ; s . pop ( ) ; } s . push ( i ) ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( daysOfWait [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 73 , 74 , 75 , 71 , 69 , 72 , 76 , 73 } ; dailyTemperatures ( arr ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int timeT = 0 ; static void dfs ( int u , int p , int dis , int vis [ ] , int distance [ ] , int parent [ ] , int preTime [ ] , int postTime [ ] , ArrayList < ArrayList < Integer > > Adj ) { distance [ u ] = dis ; parent [ u ] = p ; vis [ u ] = 1 ; timeT ++ ; preTime [ u ] = timeT ; for ( int i = 0 ; i < Adj . get ( u ) . size ( ) ; i ++ ) { if ( vis [ Adj . get ( u ) . get ( i ) ] == 0 ) { dfs ( Adj . get ( u ) . get ( i ) , u , dis + 1 , vis , distance , parent , preTime , postTime , Adj ) ; } } timeT ++ ; postTime [ u ] = timeT ; } static void addEdge ( ArrayList < ArrayList < Integer > > Adj , int u , int v ) { Adj . get ( u ) . add ( v ) ; Adj . get ( v ) . add ( u ) ; } static void findNodeU ( int N , int V , int Vertices [ ] , int Edges [ ] [ ] ) { int vis [ ] = new int [ N + 1 ] ; int distance [ ] = new int [ N + 1 ] ; int parent [ ] = new int [ N + 1 ] ; int preTime [ ] = new int [ N + 1 ] ; int postTime [ ] = new int [ N + 1 ] ; ArrayList < ArrayList < Integer > > Adj = new ArrayList < > ( ) ; for ( int i = 0 ; i < N + 1 ; i ++ ) Adj . add ( new ArrayList < Integer > ( ) ) ; int u = 0 , v ; for ( int i = 0 ; i < N - 1 ; i ++ ) { addEdge ( Adj , Edges [ i ] [ 0 ] , Edges [ i ] [ 1 ] ) ; } dfs ( 1 , 0 , 0 , vis , distance , parent , preTime , postTime , Adj ) ; int maximumDistance = 0 ; maximumDistance = 0 ; for ( int k = 0 ; k < V ; k ++ ) { if ( maximumDistance < distance [ Vertices [ k ] ] ) { maximumDistance = distance [ Vertices [ k ] ] ; u = Vertices [ k ] ; } if ( parent [ Vertices [ k ] ] != 0 ) { Vertices [ k ] = parent [ Vertices [ k ] ] ; } } boolean ans = true ; boolean flag ; for ( int k = 0 ; k < V ; k ++ ) { if ( preTime [ Vertices [ k ] ] <= preTime [ u ] && postTime [ Vertices [ k ] ] >= postTime [ u ] ) flag = true ; else flag = false ; ans = ans & flag ; } if ( ans ) System . out . println ( u ) ; else System . out . println ( " NO " ) ; } public static void main ( String [ ] args ) { int N = 10 ; int V = 5 ; int Vertices [ ] = { 4 , 3 , 8 , 9 , 10 } ; int Edges [ ] [ ] = { { 1 , 2 } , { 1 , 3 } , { 1 , 4 } , { 2 , 5 } , { 2 , 6 } , { 3 , 7 } , { 7 , 8 } , { 7 , 9 } , { 9 , 10 } } ; findNodeU ( N , V , Vertices , Edges ) ; } }

Index/key variables: i, k, u
Accumulator variables: i, k, timeT
Iterator variables: i, k
Boolean variables: ans, flag
Class/struct names: GFG
Java program:
import java . util . * ; public class Main { public static void uniqueElement ( int arr [ ] ) { Set < Integer > set = new HashSet < > ( ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { set . add ( arr [ i ] ) ; } if ( set . size ( ) == 1 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 9 , 9 , 9 , 9 , 9 , 9 , 9 } ; uniqueElement ( arr ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Main
Java program:
import java . util . * ; class GFG { static int ans = 0 , allsum = 0 ; static Vector < Integer > [ ] edges = new Vector [ 100001 ] ; static void addedge ( int a , int b ) { edges [ a ] . add ( b ) ; edges [ b ] . add ( a ) ; } static void findCost ( int r , int p , int arr [ ] ) { int i , cur ; for ( i = 0 ; i < edges [ r ] . size ( ) ; i ++ ) { cur = edges [ r ] . get ( i ) ; if ( cur == p ) continue ; findCost ( cur , r , arr ) ; arr [ r ] += arr [ cur ] ; } int t1 = arr [ r ] ; int t2 = allsum - t1 ; if ( t1 * t2 > ans ) { ans = t1 * t2 ; } } static void maximumCost ( int r , int p , int N , int M , int arr [ ] , int Edges [ ] [ ] ) { for ( int i = 0 ; i < N ; i ++ ) { allsum += arr [ i ] ; } for ( int i = 0 ; i < M ; i ++ ) { addedge ( Edges [ i ] [ 0 ] , Edges [ i ] [ 1 ] ) ; } findCost ( r , p , arr ) ; } public static void main ( String [ ] args ) { int a , b , N = 6 ; int arr [ ] = { 13 , 8 , 7 , 4 , 5 , 9 } ; int M = 5 ; int Edges [ ] [ ] = { { 0 , 1 } , { 1 , 2 } , { 1 , 4 } , { 3 , 4 } , { 4 , 5 } } ; for ( int i = 0 ; i < edges . length ; i ++ ) edges [ i ] = new Vector < Integer > ( ) ; maximumCost ( 1 , - 1 , N , M , arr , Edges ) ; System . out . print ( ans ) ; } }

Index/key variables: a, b, cur, i, r
Accumulator variables: allsum, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int X = 1 ; static int diameter = 0 ; static HashMap < Integer , Boolean > mp = new HashMap < > ( ) ; static void dfs ( int current_node , int prev_node , int len , boolean add_to_map , Vector < Integer > [ ] adj ) { if ( len > diameter ) { diameter = len ; X = current_node ; } if ( add_to_map && len == diameter ) { mp . put ( current_node , true ) ; } for ( int it : adj [ current_node ] ) { if ( it != prev_node ) dfs ( it , current_node , len + 1 , add_to_map , adj ) ; } } static void dfsUtility ( Vector < Integer > [ ] adj ) { dfs ( 1 , - 1 , 0 , false , adj ) ; int farthest_node = X ; dfs ( farthest_node , - 1 , 0 , false , adj ) ; dfs ( farthest_node , - 1 , 0 , true , adj ) ; dfs ( X , - 1 , 0 , true , adj ) ; } static void printDiameters ( Vector < Integer > [ ] adj ) { dfsUtility ( adj ) ; for ( int i = 1 ; i <= 6 ; i ++ ) { if ( mp . containsKey ( i ) && mp . get ( i ) == true ) System . out . print ( diameter + 1 + " , ▁ " ) ; else System . out . print ( diameter + " , ▁ " ) ; } } public static void main ( String [ ] args ) { Vector < Integer > [ ] adj = new Vector [ 7 ] ; for ( int i = 0 ; i < adj . length ; i ++ ) adj [ i ] = new Vector < Integer > ( ) ; adj [ 1 ] . add ( 2 ) ; adj [ 2 ] . add ( 1 ) ; adj [ 1 ] . add ( 3 ) ; adj [ 3 ] . add ( 1 ) ; adj [ 2 ] . add ( 4 ) ; adj [ 4 ] . add ( 2 ) ; adj [ 2 ] . add ( 5 ) ; adj [ 5 ] . add ( 2 ) ; adj [ 2 ] . add ( 6 ) ; adj [ 6 ] . add ( 2 ) ; printDiameters ( adj ) ; } }

Index/key variables: current_node, i
Accumulator variables: i
Iterator variables: i, it
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { static int inf = ( int ) 1e18 ; static int minimumReplacement ( int [ ] arr , int N , int K ) { int ans = inf ; ArrayList < Integer > max_values = new ArrayList < > ( ) ; ArrayList < Integer > min_values = new ArrayList < > ( ) ; Map < Integer , Integer > sum_equal_to_x = new HashMap < > ( ) ; for ( int i = 0 ; i < N / 2 ; i ++ ) { int mn = Math . min ( arr [ i ] , arr [ N - i - 1 ] ) ; int mx = Math . max ( arr [ i ] , arr [ N - i - 1 ] ) ; sum_equal_to_x . put ( arr [ i ] + arr [ N - i - 1 ] , sum_equal_to_x . getOrDefault ( arr [ i ] + arr [ N - i - 1 ] , 0 ) + 1 ) ; min_values . add ( mn ) ; max_values . add ( mx ) ; } Collections . sort ( max_values ) ; Collections . sort ( min_values ) ; for ( int x = 2 ; x <= 2 * K ; x ++ ) { int mp1 = max_values . indexOf ( x - K ) ; int mp2 = min_values . indexOf ( x ) ; int rep2 = mp1 + ( N / 2 - mp2 ) ; int rep0 = sum_equal_to_x . getOrDefault ( x , - 1 ) ; int rep1 = ( N / 2 - rep2 - rep0 ) ; ans = Math . min ( ans , rep2 * 2 + rep1 ) ; } return ans ; } public static void main ( String [ ] args ) { int N = 4 ; int K = 3 ; int arr [ ] = { 1 , 2 , 2 , 1 } ; System . out . print ( minimumReplacement ( arr , N , K ) ) ; } }

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