dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static int countSubsets ( int arr [ ] , int n ) { HashSet < Integer > us = new HashSet < > ( ) ; int even_count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] % 2 == 0 ) us . add ( arr [ i ] ) ; even_count = us . size ( ) ; return ( int ) ( Math . pow ( 2 , even_count ) - 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 2 , 1 , 9 , 2 , 6 , 5 , 3 } ; int n = arr . length ; System . out . println ( " Number ▁ of ▁ subsets ▁ = ▁ " + countSubsets ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class Test { static int countWindowDistinct ( int win [ ] , int k ) { int dist_count = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int j ; for ( j = 0 ; j < i ; j ++ ) if ( win [ i ] == win [ j ] ) break ; if ( j == i ) dist_count ++ ; } return dist_count ; } static void countDistinct ( int arr [ ] , int n , int k ) { for ( int i = 0 ; i <= n - k ; i ++ ) System . out . println ( countWindowDistinct ( Arrays . copyOfRange ( arr , i , arr . length ) , k ) ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 1 , 3 , 4 , 2 , 3 } , k = 4 ; countDistinct ( arr , arr . length , k ) ; } }

Index/key variables: i, j
Accumulator variables: dist_count, i, j
Iterator variables: i, j
Class/struct names: Test
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 = null ; temp . right = null ; return temp ; } static String areMirrors ( Node root1 , Node root2 ) { Stack < Node > st1 = new Stack < Node > ( ) ; Stack < Node > st2 = new Stack < Node > ( ) ; while ( true ) { while ( root1 != null && root2 != null ) { if ( root1 . data != root2 . data ) return " No " ; st1 . push ( root1 ) ; st2 . push ( root2 ) ; root1 = root1 . left ; root2 = root2 . right ; } if ( ! ( root1 == null && root2 == null ) ) return " No " ; if ( ! st1 . isEmpty ( ) && ! st2 . isEmpty ( ) ) { root1 = st1 . peek ( ) ; root2 = st2 . peek ( ) ; st1 . pop ( ) ; st2 . pop ( ) ; root1 = root1 . right ; root2 = root2 . left ; } else break ; } return " Yes " ; } public static void main ( String [ ] args ) { Node root1 = newNode ( 1 ) ; root1 . left = newNode ( 3 ) ; root1 . right = newNode ( 2 ) ; root1 . right . left = newNode ( 5 ) ; root1 . right . right = newNode ( 4 ) ; Node root2 = newNode ( 1 ) ; root2 . left = newNode ( 2 ) ; root2 . right = newNode ( 3 ) ; root2 . left . left = newNode ( 4 ) ; root2 . left . right = newNode ( 5 ) ; System . out . println ( areMirrors ( root1 , root2 ) ) ; } }

Class/struct names: GfG, Node
Java program:
import java . util . * ; class GFG { public static int maximumSum ( int [ ] a , int [ ] b , int n , int index , int lastpicked , int [ ] [ ] dp ) { if ( index == n ) return 0 ; if ( dp [ index ] [ lastpicked + 1 ] != - 1 ) return dp [ index ] [ lastpicked + 1 ] ; int option1 = 0 , option2 = 0 ; if ( lastpicked == - 1 a [ lastpicked ] != a [ index ] ) { option1 = b [ index ] + maximumSum ( a , b , n , index + 1 , index , dp ) ; } option2 = maximumSum ( a , b , n , index + 1 , lastpicked , dp ) ; return dp [ index ] [ lastpicked + 1 ] = Math . max ( option1 , option2 ) ; } public static void maximumPoints ( int arr [ ] , int brr [ ] , int n ) { int index = 0 , lastPicked = - 1 ; int dp [ ] [ ] = new int [ n + 5 ] [ n + 5 ] ; for ( int i [ ] : dp ) Arrays . fill ( i , - 1 ) ; System . out . println ( maximumSum ( arr , brr , n , index , lastPicked , dp ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 3 , 3 , 1 } ; int brr [ ] = { - 1 , 2 , 10 , 20 , - 10 , - 9 } ; int N = arr . length ; maximumPoints ( arr , brr , N ) ; } }

Index/key variables: index, lastpicked
Class/struct names: GFG
Java program:
import java . util . HashSet ; import java . util . Set ; public class MaxPossibleSuminWindow { static int returnMaxSum ( int A [ ] , int B [ ] , int n ) { Set < Integer > mp = new HashSet < Integer > ( ) ; int result = 0 ; int curr_sum = 0 , curr_begin = 0 ; for ( int i = 0 ; i < n ; ++ i ) { while ( mp . contains ( A [ i ] ) ) { mp . remove ( A [ curr_begin ] ) ; curr_sum -= B [ curr_begin ] ; curr_begin ++ ; } mp . add ( A [ i ] ) ; curr_sum += B [ i ] ; result = Integer . max ( result , curr_sum ) ; } return result ; } public static void main ( String [ ] args ) { int A [ ] = { 0 , 1 , 2 , 3 , 0 , 1 , 4 } ; int B [ ] = { 9 , 8 , 1 , 2 , 3 , 4 , 5 } ; int n = A . length ; System . out . println ( returnMaxSum ( A , B , n ) ) ; } }

Index/key variables: curr_begin, i
Accumulator variables: curr_begin, curr_sum
Iterator variables: i
Class/struct names: MaxPossibleSuminWindow
Java program:
import java . io . * ; import java . util . * ; class GFG { static void FindMax ( int arr [ ] , int N ) { int maxi = - 1 ; int maxi2 = - 1 ; int count = 0 ; for ( int i = 0 ; i < N ; ++ i ) { if ( arr [ i ] == 0 ) count = 0 ; else { count ++ ; maxi = Math . max ( maxi , count ) ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) { count ++ ; if ( count > maxi2 && count < maxi ) { maxi2 = count ; } } if ( arr [ i ] == 0 ) count = 0 ; } maxi = Math . max ( maxi , 0 ) ; maxi2 = Math . max ( maxi2 , 0 ) ; System . out . println ( maxi2 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 , 0 , 0 , 1 , 1 } ; int n = arr . length ; FindMax ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Map < Integer , Boolean > mp = new HashMap < Integer , Boolean > ( ) ; static class Node { int key ; Node left , right ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return ( temp ) ; } static void calculateMin ( Node root , Vector < Integer > levelMin ) { Queue < Node > qt = new LinkedList < > ( ) ; qt . add ( root ) ; int count = 1 ; int min_v = Integer . MAX_VALUE ; while ( ! qt . isEmpty ( ) ) { Node temp = qt . peek ( ) ; min_v = Math . min ( min_v , temp . key ) ; qt . remove ( ) ; if ( temp . left != null ) { qt . add ( temp . left ) ; } if ( temp . right != null ) { qt . add ( temp . right ) ; } count -- ; if ( count == 0 ) { levelMin . add ( min_v ) ; min_v = Integer . MAX_VALUE ; count = qt . size ( ) ; } } } static void findNodes ( Node root , Vector < Integer > levelMin , int [ ] levelResult , int level ) { if ( root == null ) return ; findNodes ( root . left , levelMin , levelResult , level + 1 ) ; findNodes ( root . right , levelMin , levelResult , level + 1 ) ; for ( int i = 0 ; i < level ; i ++ ) { if ( root . key <= levelMin . get ( i ) ) { levelResult [ i ] += 1 ; } } } static void printNodes ( Node root ) { Vector < Integer > levelMin = new Vector < Integer > ( ) ; calculateMin ( root , levelMin ) ; int numLevels = levelMin . size ( ) ; int [ ] levelResult = new int [ numLevels ] ; findNodes ( root , levelMin , levelResult , 0 ) ; for ( int i = 0 ; i < numLevels ; i ++ ) { System . out . print ( levelResult [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { Node root = newNode ( 4 ) ; root . left = newNode ( 3 ) ; root . right = newNode ( 5 ) ; root . right . left = newNode ( 3 ) ; root . right . right = newNode ( 1 ) ; root . left . left = newNode ( 10 ) ; root . left . right = newNode ( 2 ) ; printNodes ( root ) ; } }

Index/key variables: i, numLevels
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG, Node
Java program:
import java . util . * ; class MyDS { public MyDS ( ) { arr = new ArrayList < Integer > ( ) ; hash = new HashMap < Integer , Integer > ( ) ; } ArrayList < Integer > arr ; HashMap < Integer , Integer > hash ; void add ( int x ) { if ( hash . get ( x ) != null ) return ; int s = arr . size ( ) ; arr . add ( x ) ; hash . put ( x , s ) ; } void remove ( int x ) { Integer index = hash . get ( x ) ; if ( index == null ) return ; hash . remove ( x ) ; int size = arr . size ( ) ; Integer last = arr . get ( size - 1 ) ; Collections . swap ( arr , index , size - 1 ) ; arr . remove ( size - 1 ) ; hash . put ( last , index ) ; } int getRandom ( ) { Random rand = new Random ( ) ; int index = rand . nextInt ( arr . size ( ) ) ; return arr . get ( index ) ; } Integer search ( int x ) { return hash . get ( x ) ; } } class Main { public static void main ( String [ ] args ) { MyDS ds = new MyDS ( ) ; ds . add ( 10 ) ; ds . add ( 20 ) ; ds . add ( 30 ) ; ds . add ( 40 ) ; System . out . println ( ds . search ( 30 ) ) ; ds . remove ( 20 ) ; ds . add ( 50 ) ; System . out . println ( ds . search ( 50 ) ) ; System . out . println ( ds . getRandom ( ) ) ; } }

Class/struct names: Main, MyDS
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int countSubArray ( int arr [ ] , int n ) { if ( n < 2 ) return n ; int i = max_element ( arr ) ; int j = min_element ( arr ) ; if ( i > j ) { int tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; } return ( i + 1 ) * ( n - j ) ; } static int max_element ( int [ ] arr ) { int idx = 0 ; int max = arr [ 0 ] ; for ( int i = 1 ; i < arr . length ; i ++ ) { if ( max < arr [ i ] ) { max = arr [ i ] ; idx = i ; } } return idx ; } static int min_element ( int [ ] arr ) { int idx = 0 ; int min = arr [ 0 ] ; for ( int i = 1 ; i < arr . length ; i ++ ) { if ( arr [ i ] < min ) { min = arr [ i ] ; idx = i ; } } return idx ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 1 , 2 , 3 } ; int n = arr . length ; System . out . println ( countSubArray ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class GFG { Node root ; static int result ; static int [ ] dfs ( Node root , int distance ) { if ( root == null ) return new int [ distance + 1 ] ; if ( root . left == null && root . right == null ) { int res [ ] = new int [ distance + 1 ] ; res [ 1 ] ++ ; return res ; } int [ ] left = dfs ( root . left , distance ) ; int [ ] right = dfs ( root . right , distance ) ; int res [ ] = new int [ distance + 1 ] ; for ( int i = res . length - 2 ; i >= 1 ; i -- ) { res [ i + 1 ] = left [ i ] + right [ i ] ; } for ( int l = 1 ; l < left . length ; l ++ ) { for ( int r = 0 ; r < right . length ; r ++ ) { if ( l + r <= distance ) { result += left [ l ] * right [ r ] ; } } } return res ; } public static void main ( String [ ] args ) { GFG tree = new GFG ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; result = 0 ; int K = 3 ; dfs ( tree . root , K ) ; System . out . println ( result ) ; } }

Index/key variables: i, l, r
Accumulator variables: i, l, r, result
Iterator variables: i, l, r
Class/struct names: GFG, Node
Java program:
import java . util . * ; class Pair < F , S > { private F first ; private S second ; public Pair ( F first , S second ) { this . first = first ; this . second = second ; } } class GFG { public static int right_angled ( int n ) { Set < Pair < Integer , Pair < Integer , Integer > > > s = new HashSet < Pair < Integer , Pair < Integer , Integer > > > ( ) ; for ( int x = 1 ; x <= n ; x ++ ) { for ( int y = 1 ; y <= n ; y ++ ) { if ( x * x + y * y <= n * n ) { int z = ( int ) Math . sqrt ( x * x + y * y ) ; if ( z * z != ( x * x + y * y ) ) continue ; Vector < Integer > v = new Vector < Integer > ( ) ; v . add ( x ) ; v . add ( y ) ; v . add ( ( int ) Math . sqrt ( x * x + y * y ) ) ; Collections . sort ( v ) ; s . add ( new Pair < Integer , Pair < Integer , Integer > > ( v . get ( 0 ) , new Pair < Integer , Integer > ( v . get ( 1 ) , v . get ( 2 ) ) ) ) ; } else break ; } } return s . size ( ) - 1 ; } public static void main ( String [ ] args ) { int n = 5 ; System . out . println ( right_angled ( n ) ) ; } }

Accumulator variables: x, y
Iterator variables: x, y
Class/struct names: GFG, Pair
Java program:
import java . util . * ; class GFG { static void maxAbsDiffLevelSum ( int N , int M , int [ ] cost , int Edges [ ] [ ] ) { @ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] adj = new Vector [ N ] ; for ( int i = 0 ; i < adj . length ; i ++ ) adj [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; adj [ u ] . add ( v ) ; } int maxSum = cost [ 0 ] , minSum = cost [ 0 ] ; Queue < Integer > q = new LinkedList < Integer > ( ) ; q . add ( 0 ) ; while ( ! q . isEmpty ( ) ) { int count = q . size ( ) ; int sum = 0 ; while ( count -- > 0 ) { int temp = q . peek ( ) ; q . remove ( ) ; sum = sum + cost [ temp ] ; for ( int i = 0 ; i < adj [ temp ] . size ( ) ; i ++ ) { q . add ( adj [ temp ] . get ( i ) ) ; } } maxSum = Math . max ( sum , maxSum ) ; minSum = Math . min ( sum , minSum ) ; } System . out . print ( Math . abs ( maxSum - minSum ) ) ; } public static void main ( String [ ] args ) { int N = 10 , M = 9 ; int Edges [ ] [ ] = { { 0 , 1 } , { 0 , 2 } , { 0 , 3 } , { 1 , 4 } , { 1 , 5 } , { 3 , 6 } , { 6 , 7 } , { 6 , 8 } , { 6 , 9 } } ; int [ ] cost = { 1 , 2 , - 1 , 3 , 4 , 5 , 8 , 6 , 12 , 7 } ; maxAbsDiffLevelSum ( N , M , cost , Edges ) ; } }

Index/key variables: N, i, temp, u
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static long findMinCost ( int [ ] a , int k , int n ) { int max_ele = Arrays . stream ( a ) . max ( ) . getAsInt ( ) ; long [ ] dp = new long [ n + 1 ] ; for ( int i = 1 ; i <= n ; ++ i ) dp [ i ] = Integer . MAX_VALUE ; dp [ 0 ] = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int [ ] freq = new int [ max_ele + 1 ] ; for ( int j = i ; j < n ; ++ j ) { freq [ a [ j ] ] ++ ; int cost = 0 ; for ( int x = 0 ; x <= max_ele ; ++ x ) { cost += ( freq [ x ] == 1 ) ? 0 : freq [ x ] ; } dp [ j + 1 ] = Math . min ( dp [ i ] + cost + k , dp [ j + 1 ] ) ; } } return dp [ n ] ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 1 , 1 , 1 } ; int K = 2 ; int n = arr . length ; System . out . print ( findMinCost ( arr , K , n ) ) ; } }

Index/key variables: i, j, n, x
Accumulator variables: cost
Iterator variables: i, j, x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void subArraySum ( int [ ] arr , int n , int sum ) { int cur_sum = 0 ; int start = 0 ; int end = - 1 ; HashMap < Integer , Integer > hashMap = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { cur_sum = cur_sum + arr [ i ] ; if ( cur_sum - sum == 0 ) { start = 0 ; end = i ; break ; } if ( hashMap . containsKey ( cur_sum - sum ) ) { start = hashMap . get ( cur_sum - sum ) + 1 ; end = i ; break ; } hashMap . put ( cur_sum , i ) ; } if ( end == - 1 ) { System . out . println ( " No ▁ subarray ▁ with ▁ given ▁ sum ▁ exists " ) ; } else { System . out . println ( " Sum ▁ found ▁ between ▁ indexes ▁ " + start + " ▁ to ▁ " + end ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 10 , 2 , - 2 , - 20 , 10 } ; int n = arr . length ; int sum = - 10 ; subArraySum ( arr , n , sum ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root1 , root2 ; boolean identicalTrees ( Node a , Node b ) { if ( a == null && b == null ) return true ; if ( a != null && b != null ) return ( a . data == b . data && identicalTrees ( a . left , b . left ) && identicalTrees ( a . right , b . right ) ) ; return false ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root1 = new Node ( 1 ) ; tree . root1 . left = new Node ( 2 ) ; tree . root1 . right = new Node ( 3 ) ; tree . root1 . left . left = new Node ( 4 ) ; tree . root1 . left . right = new Node ( 5 ) ; tree . root2 = new Node ( 1 ) ; tree . root2 . left = new Node ( 2 ) ; tree . root2 . right = new Node ( 3 ) ; tree . root2 . left . left = new Node ( 4 ) ; tree . root2 . left . right = new Node ( 5 ) ; if ( tree . identicalTrees ( tree . root1 , tree . root2 ) ) System . out . println ( " Both ▁ trees ▁ are ▁ identical " ) ; else System . out . println ( " Trees ▁ are ▁ not ▁ identical " ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; class GFG { static int maxn = 100005 ; static int [ ] [ ] BITree = new int [ 26 ] [ maxn ] ; static int N ; static void update_BITree ( int index , char C , int val ) { while ( index <= N ) { BITree [ C - ' a ' ] [ index ] += val ; index += ( index & - index ) ; } } static int sum_BITree ( int index , char C ) { int s = 0 ; while ( index > 0 ) { s += BITree [ C - ' a ' ] [ index ] ; index -= ( index & - index ) ; } return s ; } static void buildTree ( String str ) { for ( int i = 1 ; i <= N ; i ++ ) { update_BITree ( i , str . charAt ( i ) , 1 ) ; } System . out . println ( ) ; } static char printCharacter ( String str , int l , int r , int k ) { int count = 0 ; char ans = 0 ; for ( char C = ' z ' ; C >= ' a ' ; C -- ) { int times = sum_BITree ( r , C ) - sum_BITree ( l - 1 , C ) ; count += times ; if ( count >= k ) { ans = C ; break ; } } return ans ; } static void updateTree ( String str , int pos , char s ) { int index = pos ; update_BITree ( index , str . charAt ( index ) , - 1 ) ; str = str . substring ( 0 , index ) + s + str . substring ( index + 1 ) ; update_BITree ( index , s , 1 ) ; } public static void main ( String [ ] args ) { String str = " abcddef " ; N = str . length ( ) ; str = ' / ' + str ; int Q = 3 ; buildTree ( str ) ; System . out . print ( printCharacter ( str , 1 , 2 , 2 ) + "NEW_LINE"); updateTree ( str , 4 , ' g ' ) ; System . out . print ( printCharacter ( str , 1 , 5 , 4 ) + "NEW_LINE"); } }

Index/key variables: index, maxn
Accumulator variables: C, count, i, index, s
Iterator variables: C, i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static String generatePassword ( String s [ ] , char T ) { StringBuilder result = new StringBuilder ( ) ; for ( String currentString : s ) { String person [ ] = currentString . split ( " : " ) ; String name = person [ 0 ] ; String number = person [ 1 ] ; int n = name . length ( ) ; int max = 0 ; for ( int i = 0 ; i < number . length ( ) ; i ++ ) { int temp = Integer . parseInt ( String . valueOf ( number . charAt ( i ) ) ) ; if ( temp > max && temp <= n ) max = temp ; } if ( max == 0 ) result . append ( T ) ; else result . append ( String . valueOf ( name . charAt ( max - 1 ) ) ) ; } return result . toString ( ) ; } public static void main ( String [ ] args ) { String arr [ ] = { " Geeks : 89167" , " gfg : 68795" } ; char T = ' X ' ; System . out . println ( generatePassword ( arr , T ) ) ; } }

Accumulator variables: i
Iterator variables: currentString, i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { @ SuppressWarnings ( " unchecked " ) static Vector < Integer > [ ] vec = new Vector [ 100001 ] ; static boolean [ ] vis = new boolean [ 100001 ] ; static int cc = 1 ; static void dfs ( int node ) { vis [ node ] = true ; for ( int x : vec [ node ] ) { if ( ! vis [ x ] ) { cc ++ ; dfs ( x ) ; } } } static void addEdge ( int u , int v ) { vec [ u ] . add ( v ) ; vec [ v ] . add ( u ) ; } static void minEdgeRemoved ( int N , int M , int Edges [ ] [ ] ) { for ( int i = 0 ; i < M ; i ++ ) { addEdge ( Edges [ i ] [ 0 ] , Edges [ i ] [ 1 ] ) ; } int k = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( ! vis [ i ] ) { cc = 1 ; dfs ( i ) ; k ++ ; } } System . out . print ( M - N + k + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 3 , M = 2 ; int Edges [ ] [ ] = { { 1 , 2 } , { 2 , 3 } } ; for ( int i = 0 ; i < vec . length ; i ++ ) vec [ i ] = new Vector < Integer > ( ) ; minEdgeRemoved ( N , M , Edges ) ; } }

Index/key variables: i, node, u, v, x
Accumulator variables: cc, i, k
Iterator variables: i, x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean pairFound = false ; 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 void pairSum ( Node root , int target , HashSet < Integer > S ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { if ( S . contains ( target - root . data ) ) { System . out . print ( target - root . data + " ▁ " + root . data ) ; pairFound = true ; return ; } else S . add ( root . data ) ; } pairSum ( root . left , target , S ) ; pairSum ( root . right , target , S ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right = newNode ( 3 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . right . right . right = newNode ( 8 ) ; HashSet < Integer > S = new HashSet < Integer > ( ) ; int K = 13 ; pairSum ( root , K , S ) ; if ( pairFound == false ) System . out . print ( " - 1" ) ; } }

Boolean variables: pairFound
Class/struct names: GFG, Node
Java program:
public class GFG { private static void countRooks ( int n , int k , int pos [ ] [ ] ) { int row [ ] = new int [ n ] ; int col [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { row [ i ] = 0 ; col [ i ] = 0 ; } for ( int i = 0 ; i < k ; i ++ ) { row [ pos [ i ] [ 0 ] - 1 ] = 1 ; col [ pos [ i ] [ 1 ] - 1 ] = 1 ; } int res = n - k ; System . out . println ( res + " ▁ " ) ; int ri = 0 , ci = 0 ; while ( res -- > 0 ) { while ( row [ ri ] == 1 ) { ri ++ ; } while ( col [ ci ] == 1 ) { ci ++ ; } System . out . println ( ( ri + 1 ) + " ▁ " + ( ci + 1 ) + " ▁ " ) ; ri ++ ; ci ++ ; } } public static void main ( String [ ] args ) { int N = 4 ; int K = 2 ; int pos [ ] [ ] = { { 1 , 4 } , { 2 , 2 } } ; countRooks ( N , K , pos ) ; } }

Index/key variables: ci, i, n, ri
Accumulator variables: ci, i, res, ri
Iterator variables: i
Class/struct names: GFG
Java program:
public class Palindrome { static int minInsertion ( String str ) { int n = str . length ( ) ; int res = 0 ; int [ ] count = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) count [ str . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( count [ i ] % 2 == 1 ) res ++ ; } return ( res == 0 ) ? 0 : res - 1 ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; System . out . println ( minInsertion ( str ) ) ; } }

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Class/struct names: Palindrome
Java program:
import java . util . * ; class GFG { static boolean check ( String ans , String [ ] s , int n , int m ) { for ( int i = 1 ; i < n ; ++ i ) { int count = 0 ; for ( int j = 0 ; j < m ; ++ j ) { if ( ans . charAt ( j ) != s [ i ] . charAt ( j ) ) count ++ ; } if ( count > 1 ) return false ; } return true ; } static String findString ( String [ ] s ) { int n = s . length ; String ans = s [ 0 ] ; int m = ans . length ( ) ; int flag = 0 ; for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 0 ; j < 26 ; ++ j ) { String x = ans ; x = x . replace ( x . charAt ( i ) , ( char ) ( j + ' a ' ) ) ; if ( check ( x , s , n , m ) ) { ans = x ; flag = 1 ; break ; } } if ( flag == 1 ) break ; } if ( flag == 0 ) return " - 1" ; else return ans ; } public static void main ( String [ ] args ) { String s [ ] = { " geeks " , " teeds " } ; System . out . println ( findString ( s ) ) ; } }

Index/key variables: i
Accumulator variables: count
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int getMinOps ( int [ ] arr ) { int ans = 0 ; for ( int i = 0 ; i < arr . length - 1 ; i ++ ) { ans += Math . max ( arr [ i ] - arr [ i + 1 ] , 0 ) ; } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 1 , 2 , 4 } ; System . out . println ( getMinOps ( arr ) ) ; } }

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