dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int charVal ( char c ) { if ( c == ' I ' ) return 1 ; if ( c == ' V ' ) return 5 ; if ( c == ' X ' ) return 10 ; if ( c == ' L ' ) return 50 ; if ( c == ' C ' ) return 100 ; if ( c == ' D ' ) return 500 ; if ( c == ' M ' ) return 1000 ; return - 1 ; } static int romanToDec ( String S ) { int res = 0 ; int n = S . length ( ) ; res = charVal ( S . charAt ( n - 1 ) ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( charVal ( S . charAt ( i ) ) < charVal ( S . charAt ( i + 1 ) ) ) res -= charVal ( S . charAt ( i ) ) ; else res += charVal ( S . charAt ( i ) ) ; } return res ; } static String DecToRoman ( int number ) { String res = " " ; int num [ ] = { 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 } ; String sym [ ] = { " I " , " IV " , " V " , " IX " , " X " , " XL " , " L " , " XC " , " C " , " CD " , " D " , " CM " , " M " } ; int i = 12 ; while ( number > 0 ) { int div = number / num [ i ] ; number = number % num [ i ] ; while ( div -- > 0 ) { res += sym [ i ] ; } i -- ; } return res ; } static String findLargest ( String S ) { char arr [ ] = { ' I ' , ' V ' , ' X ' , ' L ' , ' C ' , ' D ' , ' M ' } ; Set < Character > st = new HashSet < > ( ) ; for ( char x : arr ) st . add ( x ) ; Character s [ ] = new Character [ S . length ( ) ] ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) s [ i ] = S . charAt ( i ) ; for ( char x : s ) { if ( ! st . contains ( x ) ) return " Invalid " ; } Arrays . sort ( s , new Comparator < Character > ( ) { @ Override public int compare ( Character x , Character y ) { return charVal ( y ) - charVal ( x ) ; } } ) ; String ss = " " ; for ( char ch : s ) ss += ch ; int N = romanToDec ( ss ) ; String R = DecToRoman ( N ) ; if ( ! ss . equals ( R ) ) return " Invalid " ; return ss ; } public static void main ( String [ ] args ) { String S = " MCMIV " ; int N = S . length ( ) ; System . out . println ( findLargest ( S ) ) ; } }

Index/key variables: i
Accumulator variables: div, i, res, ss
Iterator variables: ch, i, x
Class/struct names: GFG
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { Node root ; int minimumDepth ( ) { return minimumDepth ( root ) ; } int minimumDepth ( Node root ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) return 1 ; if ( root . left == null ) return minimumDepth ( root . right ) + 1 ; if ( root . right == null ) return minimumDepth ( root . left ) + 1 ; return Math . min ( minimumDepth ( root . left ) , minimumDepth ( root . right ) ) + 1 ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " The ▁ minimum ▁ depth ▁ of ▁ " + " binary ▁ tree ▁ is ▁ : ▁ " + tree . minimumDepth ( ) ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; class GFG { static void maxFreqElements ( int arr [ ] , int N , int K ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } while ( K > 0 ) { int max = 0 ; int element = 0 ; for ( Map . Entry < Integer , Integer > i : mp . entrySet ( ) ) { if ( i . getValue ( ) > max ) { max = i . getValue ( ) ; element = i . getKey ( ) ; } } System . out . print ( element + " ▁ " ) ; if ( mp . containsKey ( element ) ) { mp . put ( element , mp . get ( element ) + 1 ) ; } else { mp . put ( element , 1 ) ; } K -- ; } } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 2 , 1 , 4 , 1 } ; int N = arr . length ; int K = 2 ; maxFreqElements ( arr , N , K ) ; } }

Index/key variables: i
Accumulator variables: K, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int [ ] reverse ( int a [ ] ) { int i , n = a . length , t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } static int maxDiffLargSmallOper ( int arr [ ] , int N , int K ) { int maxDiff = 0 ; Arrays . sort ( arr ) ; arr = reverse ( arr ) ; for ( int i = 0 ; i <= Math . min ( K , N - 1 ) ; i ++ ) { maxDiff += arr [ i ] ; } return maxDiff ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 7 , 7 , 7 } ; int N = arr . length ; int K = 1 ; System . out . print ( maxDiffLargSmallOper ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: i, maxDiff
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { public static int minCost ( String s , int R [ ] , int C [ ] , int N ) { char ch [ ] = s . toCharArray ( ) ; PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ; int flip = 0 ; int cost = 0 ; for ( int i = 0 ; i < N ; i ++ ) { while ( pq . size ( ) > 0 && pq . peek ( ) < i ) { pq . poll ( ) ; flip -- ; } int cn = ch [ i ] - '0' ; if ( flip % 2 == 1 ) cn = 1 - cn ; if ( cn == 1 ) { flip ++ ; cost += C [ i ] ; pq . add ( R [ i ] ) ; } } return cost ; } public static void main ( String [ ] args ) { int N = 4 ; String s = "1010" ; int R [ ] = { 1 , 2 , 2 , 3 } ; int C [ ] = { 3 , 1 , 2 , 3 } ; System . out . println ( minCost ( s , R , C , N ) ) ; } }

Index/key variables: i
Accumulator variables: cost, flip, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } static class qItem { Node node ; int depth ; public qItem ( Node node , int depth ) { this . node = node ; this . depth = depth ; } } static int minDepth ( Node root ) { if ( root == null ) return 0 ; Queue < qItem > q = new LinkedList < > ( ) ; qItem qi = new qItem ( root , 1 ) ; q . add ( qi ) ; while ( q . isEmpty ( ) == false ) { qi = q . peek ( ) ; q . remove ( ) ; Node node = qi . node ; int depth = qi . depth ; if ( node . left == null && node . right == null ) return depth ; if ( node . left != null ) { qi . node = node . left ; qi . depth = depth + 1 ; q . add ( qi ) ; } if ( node . right != null ) { qi . node = node . right ; qi . depth = depth + 1 ; q . add ( qi ) ; } } return 0 ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; System . out . println ( minDepth ( root ) ) ; } }

Class/struct names: GFG, Node, qItem
Java program:
import java . io . * ; import java . util . * ; class GFG { public static class Pair { int x ; int y ; Pair ( int x , int y ) { this . x = x ; this . y = y ; } } static void MaxDist ( ArrayList < Pair > A , int N ) { ArrayList < Integer > V = new ArrayList < > ( ) ; ArrayList < Integer > V1 = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { V . add ( A . get ( i ) . x + A . get ( i ) . y ) ; V1 . add ( A . get ( i ) . x - A . get ( i ) . y ) ; } Collections . sort ( V ) ; Collections . sort ( V1 ) ; int maximum = Math . max ( ( V . get ( V . size ( ) - 1 ) - V . get ( 0 ) ) , ( V1 . get ( V1 . size ( ) - 1 ) - V1 . get ( 0 ) ) ) ; System . out . println ( maximum ) ; } public static void main ( String [ ] args ) { int n = 3 ; ArrayList < Pair > al = new ArrayList < > ( ) ; Pair p1 = new Pair ( 1 , 2 ) ; al . add ( p1 ) ; Pair p2 = new Pair ( 2 , 3 ) ; al . add ( p2 ) ; Pair p3 = new Pair ( 3 , 4 ) ; al . add ( p3 ) ; MaxDist ( al , n ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Pair
Java program:
import java . awt . * ; import java . util . ArrayList ; public class Main { static long dist ( Point p1 , Point p2 ) { long x0 = p1 . x - p2 . x ; long y0 = p1 . y - p2 . y ; return x0 * x0 + y0 * y0 ; } static double maxDist ( Point p [ ] ) { int n = p . length ; double max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { max = Math . max ( max , dist ( p [ i ] , p [ j ] ) ) ; } } return Math . sqrt ( max ) ; } public static void main ( String [ ] args ) { int n = 5 ; Point p [ ] = new Point [ n ] ; p [ 0 ] = new Point ( 4 , 0 ) ; p [ 1 ] = new Point ( 0 , 2 ) ; p [ 2 ] = new Point ( - 1 , - 7 ) ; p [ 3 ] = new Point ( 1 , 10 ) ; p [ 4 ] = new Point ( 2 , - 3 ) ; System . out . println ( maxDist ( p ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
import java . util . * ; class GFG { public static void printArr ( int [ ] arr , int n ) { Arrays . sort ( arr ) ; if ( arr [ 0 ] == arr [ n - 1 ] ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 2 , 1 , 3 , 1 } ; int N = arr . length ; printArr ( arr , N ) ; } }

Index/key variables: i
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 MinimumTreeHeight { Node root ; int minimumDepth ( ) { return minimumDepth ( root , 0 ) ; } int minimumDepth ( Node root , int level ) { if ( root == null ) return level ; level ++ ; return Math . min ( minimumDepth ( root . left , level ) , minimumDepth ( root . right , level ) ) ; } public static void main ( String args [ ] ) { MinimumTreeHeight tree = new MinimumTreeHeight ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " The ▁ minimum ▁ depth ▁ of ▁ " + " binary ▁ tree ▁ is ▁ : ▁ " + tree . minimumDepth ( ) ) ; } }

Accumulator variables: level
Class/struct names: MinimumTreeHeight, Node
Java program:
import java . util . * ; class GFG { static void maximumSum ( int a [ ] , int b [ ] , int k , int n ) { int i , j ; Arrays . sort ( a ) ; Arrays . sort ( b ) ; for ( i = 0 , j = n - 1 ; i < k ; i ++ , j -- ) { if ( a [ i ] < b [ j ] ) { int temp = a [ i ] ; a [ i ] = b [ j ] ; b [ j ] = temp ; } else break ; } int sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += a [ i ] ; System . out . print ( sum + "NEW_LINE"); } public static void main ( String [ ] args ) { int K = 1 ; int A [ ] = { 2 , 3 , 4 } ; int B [ ] = { 6 , 8 , 5 } ; int N = A . length ; maximumSum ( A , B , K , N ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { static int max_dist_ele ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int ans = 0 ; int prev = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prev < ( arr [ i ] - 1 ) ) { ans ++ ; prev = arr [ i ] - 1 ; } else if ( prev < ( arr [ i ] ) ) { ans ++ ; prev = arr [ i ] ; } else if ( prev < ( arr [ i ] + 1 ) ) { ans ++ ; prev = arr [ i ] + 1 ; } } return ans ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 1 , 1 , 8 , 8 , 8 , 9 , 9 } ; int n = arr . length ; System . out . println ( max_dist_ele ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void CheckSort ( Vector < Integer > arr , int k , int n ) { Vector < Integer > sortarr = new Vector < Integer > ( ) ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { sortarr . add ( arr . get ( i ) ) ; } Collections . sort ( sortarr ) ; if ( k == 1 ) System . out . println ( " yes " ) ; else { int flag = 0 ; for ( int i = 0 ; i < n ; i ++ ) { flag = 0 ; for ( int j = i ; j < n ; j += k ) { if ( sortarr . get ( i ) == arr . get ( j ) ) { Collections . swap ( arr , i , j ) ; flag = 1 ; break ; } if ( j + k >= n ) break ; } if ( flag == 0 ) break ; } if ( flag == 0 ) System . out . println ( " Not ▁ possible ▁ to ▁ sort " ) ; else System . out . println ( " Possible ▁ to ▁ sort " ) ; } } public static void main ( String [ ] args ) { int k = 3 ; Vector < Integer > arr = new Vector < Integer > ( ) ; arr . add ( 1 ) ; arr . add ( 5 ) ; arr . add ( 6 ) ; arr . add ( 9 ) ; arr . add ( 2 ) ; arr . add ( 3 ) ; arr . add ( 5 ) ; arr . add ( 9 ) ; int n = arr . size ( ) ; CheckSort ( arr , k , n ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
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 void replaceNode ( Node node , int level ) { if ( node == null ) return ; node . data = level ; replaceNode ( node . left , level + 1 ) ; replaceNode ( node . right , level + 1 ) ; } static void printInorder ( Node node ) { if ( node == null ) return ; printInorder ( node . left ) ; System . out . print ( node . data + " ▁ " ) ; printInorder ( node . right ) ; } public static void main ( String [ ] args ) { Node root = new Node ( ) ; root = newNode ( 3 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 4 ) ; System . out . println ( " Before ▁ Replacing ▁ Nodes " ) ; printInorder ( root ) ; replaceNode ( root , 0 ) ; System . out . println ( ) ; System . out . println ( " After ▁ Replacing ▁ Nodes " ) ; printInorder ( root ) ; } }

Class/struct names: GfG, Node
Java program:
import java . util . ArrayList ; import java . util . Collections ; public class Product { static class Edge implements Comparable < Edge > { int first , second , weight ; Edge ( int x , int y , int w ) { this . first = x ; s this . second = y ; this . weight = w ; } @ Override public int compareTo ( Edge edge ) { return this . weight - edge . weight ; } } static int mod = 1000000007 ; static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static int size [ ] = new int [ 300005 ] ; static int freq [ ] = new int [ 300004 ] ; static ArrayList < Edge > edges = new ArrayList < Edge > ( ) ; static void initialize ( int Arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { Arr [ i ] = i ; size [ i ] = 1 ; } } static int root ( int Arr [ ] , int i ) { while ( Arr [ i ] != i ) { i = Arr [ i ] ; } return i ; } static void weighted_union ( int Arr [ ] , int size [ ] , int A , int B ) { int root_A = root ( Arr , A ) ; int root_B = root ( Arr , B ) ; if ( size [ root_A ] < size [ root_B ] ) { Arr [ root_A ] = Arr [ root_B ] ; size [ root_B ] += size [ root_A ] ; } else { Arr [ root_B ] = Arr [ root_A ] ; size [ root_A ] += size [ root_B ] ; } } static void AddEdge ( int a , int b , int w ) { edges . add ( new Edge ( a , b , w ) ) ; } static void MakeTree ( ) { AddEdge ( 1 , 2 , 1 ) ; AddEdge ( 1 , 3 , 3 ) ; AddEdge ( 3 , 4 , 2 ) ; } static int MinProduct ( ) { int result = 1 ; Collections . sort ( edges ) ; for ( int i = edges . size ( ) - 1 ; i >= 0 ; i -- ) { int curr_weight = edges . get ( i ) . weight ; int Node1 = edges . get ( i ) . first ; int Node2 = edges . get ( i ) . second ; int Root1 = root ( freq , Node1 ) ; int Set1_size = size [ Root1 ] ; int Root2 = root ( freq , Node2 ) ; int Set2_size = size [ Root2 ] ; int prod = Set1_size * Set2_size ; int Product = power ( curr_weight , prod , mod ) ; result = ( ( result % mod ) * ( Product % mod ) ) % mod ; weighted_union ( freq , size , Node1 , Node2 ) ; } return result % mod ; } public static void main ( String [ ] args ) { int n = 4 ; initialize ( freq , n ) ; MakeTree ( ) ; System . out . println ( MinProduct ( ) ) ; } }

Index/key variables: Root1, Root2, i, root_A, root_B
Accumulator variables: i
Iterator variables: i
Class/struct names: Edge, Product
Java program:
class GFG { public static boolean check ( int [ ] arr , int n ) { int modify = 0 ; if ( arr [ n - 1 ] >= arr [ n - 2 ] ) { arr [ n - 1 ] = arr [ n - 2 ] - 1 ; modify ++ ; } if ( arr [ 0 ] <= arr [ 1 ] ) { arr [ 0 ] = arr [ 1 ] + 1 ; modify ++ ; } for ( int i = n - 2 ; i > 0 ; i -- ) { if ( ( arr [ i - 1 ] <= arr [ i ] && arr [ i + 1 ] <= arr [ i ] ) || ( arr [ i - 1 ] >= arr [ i ] && arr [ i + 1 ] >= arr [ i ] ) ) { arr [ i ] = ( arr [ i - 1 ] + arr [ i + 1 ] ) / 2 ; modify ++ ; if ( arr [ i ] == arr [ i - 1 ] arr [ i ] == arr [ i + 1 ] ) return false ; } } if ( modify > 1 ) return false ; return true ; } public static void main ( String [ ] args ) { int [ ] arr = { 10 , 5 , 11 , 3 } ; int n = arr . length ; if ( check ( arr , n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i, modify
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Pair implements Comparable < Pair > { int first , second ; Pair ( int f , int s ) { first = f ; second = s ; } @ Override public int compareTo ( Pair o ) { if ( this . second > o . second ) return 1 ; else if ( this . second == o . second ) return 0 ; return - 1 ; } } static void maxDisjointIntervals ( Pair [ ] list ) { Collections . sort ( Arrays . asList ( list ) ) ; System . out . print ( " [ " + list [ 0 ] . first + " , ▁ " + list [ 0 ] . second + " ] " + "NEW_LINE"); int r1 = list [ 0 ] . second ; for ( int i = 1 ; i < list . length ; i ++ ) { int l1 = list [ i ] . first ; int r2 = list [ i ] . second ; if ( l1 > r1 ) { System . out . print ( " [ " + l1 + " , ▁ " + r2 + " ] " + "NEW_LINE"); r1 = r2 ; } } } public static void main ( String [ ] args ) { int N = 4 ; Pair [ ] intervals = { new Pair ( 1 , 4 ) , new Pair ( 2 , 3 ) , new Pair ( 4 , 6 ) , new Pair ( 8 , 9 ) } ; maxDisjointIntervals ( intervals ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Pair
Java program:
import java . util . * ; class GFG { static int next_pos = 1 ; static class pair { int first , second ; pair ( ) { first = 0 ; second = 0 ; } } static void printIndices ( int n , pair a [ ] ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( a [ i ] . second + " ▁ " ) ; System . out . println ( ) ; } static class sort implements Comparator < pair > { public int compare ( pair a , pair b ) { return a . first < b . first ? - 1 : 1 ; } } static void printPermutations ( int n , int a [ ] , int k ) { pair arr [ ] = new pair [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = new pair ( ) ; arr [ i ] . first = a [ i ] ; arr [ i ] . second = i ; } Arrays . sort ( arr , new sort ( ) ) ; int count = 1 ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] . first == arr [ i - 1 ] . first ) count ++ ; if ( count < k ) { System . out . print ( " - 1" ) ; return ; } for ( int i = 0 ; i < k - 1 ; i ++ ) { printIndices ( n , arr ) ; for ( int j = next_pos ; j < n ; j ++ ) { if ( arr [ j ] . first == arr [ j - 1 ] . first ) { pair t = arr [ j ] ; arr [ j ] = arr [ j - 1 ] ; arr [ j - 1 ] = t ; next_pos = j + 1 ; break ; } } } printIndices ( n , arr ) ; } public static void main ( String arsg [ ] ) { int a [ ] = { 1 , 3 , 3 , 1 } ; int n = a . length ; int k = 3 ; printPermutations ( n , a , k ) ; } }

Index/key variables: i, j, n
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG, pair, sort
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; int getMaxWidth ( Node node ) { int maxWidth = 0 ; int width ; int h = height ( node ) ; int i ; for ( i = 1 ; i <= h ; i ++ ) { width = getWidth ( node , i ) ; if ( width > maxWidth ) maxWidth = width ; } return maxWidth ; } int getWidth ( Node node , int level ) { if ( node == null ) return 0 ; if ( level == 1 ) return 1 ; else if ( level > 1 ) return getWidth ( node . left , level - 1 ) + getWidth ( node . right , level - 1 ) ; return 0 ; } int height ( Node node ) { if ( node == null ) return 0 ; else { int lHeight = height ( node . left ) ; int rHeight = height ( node . right ) ; return ( lHeight > rHeight ) ? ( lHeight + 1 ) : ( rHeight + 1 ) ; } } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . right . right = new Node ( 8 ) ; tree . root . right . right . left = new Node ( 6 ) ; tree . root . right . right . right = new Node ( 7 ) ; System . out . println ( " Maximum ▁ width ▁ is ▁ " + tree . getMaxWidth ( tree . root ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; class GFG { public static int countDistinct ( int arr [ ] , int n ) { HashSet < Integer > hs = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { hs . add ( arr [ i ] ) ; } return hs . size ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 6 , 10 , 5 , 4 , 9 , 120 , 4 , 6 , 10 } ; System . out . println ( countDistinct ( arr , arr . length ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class InPlaceMerge { private static int nextGap ( int gap ) { if ( gap <= 1 ) return 0 ; return ( int ) Math . ceil ( gap / 2.0 ) ; } private static void swap ( int [ ] nums , int i , int j ) { int temp = nums [ i ] ; nums [ i ] = nums [ j ] ; nums [ j ] = temp ; } private static void inPlaceMerge ( int [ ] nums , int start , int end ) { int gap = end - start + 1 ; for ( gap = nextGap ( gap ) ; gap > 0 ; gap = nextGap ( gap ) ) { for ( int i = start ; i + gap <= end ; i ++ ) { int j = i + gap ; if ( nums [ i ] > nums [ j ] ) swap ( nums , i , j ) ; } } } private static void mergeSort ( int [ ] nums , int s , int e ) { if ( s == e ) return ; int mid = ( s + e ) / 2 ; mergeSort ( nums , s , mid ) ; mergeSort ( nums , mid + 1 , e ) ; inPlaceMerge ( nums , s , e ) ; } public static void main ( String [ ] args ) { int [ ] nums = new int [ ] { 12 , 11 , 13 , 5 , 6 , 7 } ; mergeSort ( nums , 0 , nums . length - 1 ) ; System . out . println ( Arrays . toString ( nums ) ) ; } }

Index/key variables: i, j
Accumulator variables: i
Iterator variables: gap, i
Class/struct names: InPlaceMerge
Java program:
import java . io . * ; import java . util . * ; class GFG { static int findOptimalSolution ( int [ ] a , int N ) { Arrays . sort ( a ) ; int points = 0 ; for ( int i = 0 ; i < N ; i ++ ) { points += a [ i ] * i ; } return points ; } public static void main ( String args [ ] ) { int [ ] a = { 1 , 4 , 2 , 3 , 9 } ; int N = a . length ; System . out . println ( findOptimalSolution ( a , N ) ) ; } }

Index/key variables: i
Accumulator variables: i, points
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; public class Improve { static int number_of_tower ( int house [ ] , int range , int n ) { Arrays . sort ( house ) ; int numOfTower = 0 ; int i = 0 ; while ( i < n ) { numOfTower ++ ; int loc = house [ i ] + range ; while ( i < n && house [ i ] <= loc ) i ++ ; -- i ; loc = house [ i ] + range ; while ( i < n && house [ i ] <= loc ) i ++ ; } return numOfTower ; } public static void main ( String args [ ] ) { int house [ ] = { 7 , 2 , 4 , 6 , 5 , 9 , 12 , 11 } ; int range = 2 ; int n = house . length ; System . out . println ( number_of_tower ( house , range , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, numOfTower
Class/struct names: Improve