dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class Node { int data ; Node left , right ; Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; boolean isFullTree ( Node node ) { if ( node == null ) return true ; if ( node . left == null && node . right == null ) return true ; if ( ( node . left != null ) && ( node . right != null ) ) return ( isFullTree ( node . left ) && isFullTree ( node . right ) ) ; return false ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 10 ) ; tree . root . left = new Node ( 20 ) ; tree . root . right = new Node ( 30 ) ; tree . root . left . right = new Node ( 40 ) ; tree . root . left . left = new Node ( 50 ) ; tree . root . right . left = new Node ( 60 ) ; tree . root . left . left . left = new Node ( 80 ) ; tree . root . right . right = new Node ( 70 ) ; tree . root . left . left . right = new Node ( 90 ) ; tree . root . left . right . left = new Node ( 80 ) ; tree . root . left . right . right = new Node ( 90 ) ; tree . root . right . left . left = new Node ( 80 ) ; tree . root . right . left . right = new Node ( 90 ) ; tree . root . right . right . left = new Node ( 80 ) ; tree . root . right . right . right = new Node ( 90 ) ; if ( tree . isFullTree ( tree . root ) ) System . out . print ( " The ▁ binary ▁ tree ▁ is ▁ full " ) ; else System . out . print ( " The ▁ binary ▁ tree ▁ is ▁ not ▁ full " ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; class GFG { static void makePermutation ( int [ ] a , int n ) { HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( count . containsKey ( a [ i ] ) ) { count . put ( a [ i ] , count . get ( a [ i ] ) + 1 ) ; } else { count . put ( a [ i ] , 1 ) ; } } int next_missing = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( count . containsKey ( a [ i ] ) && count . get ( a [ i ] ) != 1 a [ i ] > n a [ i ] < 1 ) { count . put ( a [ i ] , count . get ( a [ i ] ) - 1 ) ; while ( count . containsKey ( next_missing ) ) next_missing ++ ; a [ i ] = next_missing ; count . put ( next_missing , 1 ) ; } } } public static void main ( String [ ] args ) { int A [ ] = { 2 , 2 , 3 , 3 } ; int n = A . length ; makePermutation ( A , n ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( A [ i ] + " ▁ " ) ; } }

Index/key variables: i
Accumulator variables: i, next_missing
Iterator variables: i
Class/struct names: GFG
Java program:
public class find { public static void getPairsCount ( int [ ] arr , int sum ) { int count = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) for ( int j = i + 1 ; j < arr . length ; j ++ ) if ( ( arr [ i ] + arr [ j ] ) == sum ) count ++ ; System . out . printf ( " Count ▁ of ▁ pairs ▁ is ▁ % d " , count ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 1 , 5 , 7 , - 1 , 5 } ; int sum = 6 ; getPairsCount ( arr , sum ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: find
Java program:
import java . util . * ; class GfG { static class Node { int data ; Node left , right ; } static Node getNode ( int data ) { Node newNode = new Node ( ) ; newNode . data = data ; newNode . left = null ; newNode . right = null ; return newNode ; } static boolean isFullBinaryTree ( Node root ) { if ( root == null ) return true ; Queue < Node > q = new LinkedList < Node > ( ) ; q . add ( root ) ; while ( ! q . isEmpty ( ) ) { Node node = q . peek ( ) ; q . remove ( ) ; if ( node . left == null && node . right == null ) continue ; if ( node . left == null node . right == null ) return false ; q . add ( node . left ) ; q . add ( node . right ) ; } return true ; } public static void main ( String [ ] args ) { Node root = getNode ( 1 ) ; root . left = getNode ( 2 ) ; root . right = getNode ( 3 ) ; root . left . left = getNode ( 4 ) ; root . left . right = getNode ( 5 ) ; if ( isFullBinaryTree ( root ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Class/struct names: GfG, Node
Java program:
import java . lang . * ; import java . util . * ; class GFG { static boolean linearSearch ( int a [ ] , int n , int key ) { for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == key ) return true ; } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 10 , 40 } ; int x = 10 ; int n = arr . length ; if ( linearSearch ( arr , n , x ) ) System . out . println ( " Element ▁ is ▁ present ▁ in ▁ array " ) ; else System . out . println ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . HashMap ; class Test { static int arr [ ] = new int [ ] { 1 , 5 , 7 , - 1 , 5 } ; static int getPairsCount ( int n , int sum ) { HashMap < Integer , Integer > hm = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , 0 ) ; hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ; } int twice_count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( hm . get ( sum - arr [ i ] ) != null ) twice_count += hm . get ( sum - arr [ i ] ) ; if ( sum - arr [ i ] == arr [ i ] ) twice_count -- ; } return twice_count / 2 ; } public static void main ( String [ ] args ) { int sum = 6 ; System . out . println ( " Count ▁ of ▁ pairs ▁ is ▁ " + getPairsCount ( arr . length , sum ) ) ; } }

Index/key variables: i
Accumulator variables: i, twice_count
Iterator variables: i
Class/struct names: Test
Java program:
import java . io . * ; class GFG { static int countPairs ( int [ ] arr1 , int [ ] arr2 , int m , int n , int x ) { int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( ( arr1 [ i ] + arr2 [ j ] ) == x ) count ++ ; return count ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 1 , 3 , 5 , 7 } ; int arr2 [ ] = { 2 , 3 , 5 , 8 } ; int m = arr1 . length ; int n = arr2 . length ; int x = 10 ; System . out . println ( " Count ▁ = ▁ " + countPairs ( arr1 , arr2 , m , n , x ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static boolean isPresent ( int arr [ ] , int low , int high , int value ) { while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( arr [ mid ] == value ) return true ; else if ( arr [ mid ] > value ) high = mid - 1 ; else low = mid + 1 ; } return false ; } static int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) { int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int value = x - arr1 [ i ] ; if ( isPresent ( arr2 , 0 , n - 1 , value ) ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 1 , 3 , 5 , 7 } ; int arr2 [ ] = { 2 , 3 , 5 , 8 } ; int m = arr1 . length ; int n = arr2 . length ; int x = 10 ; System . out . println ( " Count ▁ = ▁ " + countPairs ( arr1 , arr2 , m , n , x ) ) ; } }

Index/key variables: i, mid
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) { int count = 0 ; HashSet < Integer > us = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < m ; i ++ ) us . add ( arr1 [ i ] ) ; for ( int j = 0 ; j < n ; j ++ ) if ( us . contains ( x - arr2 [ j ] ) ) count ++ ; return count ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 1 , 3 , 5 , 7 } ; int arr2 [ ] = { 2 , 3 , 5 , 8 } ; int m = arr1 . length ; int n = arr2 . length ; int x = 10 ; System . out . print ( " Count ▁ = ▁ " + countPairs ( arr1 , arr2 , m , n , x ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countPairs ( int arr1 [ ] , int arr2 [ ] , int m , int n , int x ) { int count = 0 ; int l = 0 , r = n - 1 ; while ( l < m && r >= 0 ) { if ( ( arr1 [ l ] + arr2 [ r ] ) == x ) { l ++ ; r -- ; count ++ ; } else if ( ( arr1 [ l ] + arr2 [ r ] ) < x ) l ++ ; else r -- ; } return count ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 1 , 3 , 5 , 7 } ; int arr2 [ ] = { 2 , 3 , 5 , 8 } ; int m = arr1 . length ; int n = arr2 . length ; int x = 10 ; System . out . println ( " Count ▁ = ▁ " + countPairs ( arr1 , arr2 , m , n , x ) ) ; } }

Index/key variables: l, r
Accumulator variables: count, l, r
Class/struct names: GFG
Java program:
import java . util . Arrays ; import java . util . Iterator ; import java . util . LinkedList ; class GFG { static int countPairs ( LinkedList < Integer > head1 , LinkedList < Integer > head2 , int x ) { int count = 0 ; Iterator < Integer > itr1 = head1 . iterator ( ) ; while ( itr1 . hasNext ( ) ) { Iterator < Integer > itr2 = head2 . iterator ( ) ; Integer t = itr1 . next ( ) ; while ( itr2 . hasNext ( ) ) { if ( ( t + itr2 . next ( ) ) == x ) count ++ ; } } return count ; } public static void main ( String [ ] args ) { Integer arr1 [ ] = { 3 , 1 , 5 , 7 } ; Integer arr2 [ ] = { 8 , 2 , 5 , 3 } ; LinkedList < Integer > head1 = new LinkedList < > ( Arrays . asList ( arr1 ) ) ; LinkedList < Integer > head2 = new LinkedList < > ( Arrays . asList ( arr2 ) ) ; int x = 10 ; System . out . println ( " Count ▁ = ▁ " + countPairs ( head1 , head2 , x ) ) ; } }

Accumulator variables: count
Class/struct names: GFG
Java program:
class GFG { static boolean isPresent ( int [ ] arr , int low , int high , int value ) { while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( arr [ mid ] == value ) return true ; else if ( arr [ mid ] > value ) high = mid - 1 ; else low = mid + 1 ; } return false ; } static int countQuadruples ( int [ ] arr1 , int [ ] arr2 , int [ ] arr3 , int [ ] arr4 , int n , int x ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) for ( int k = 0 ; k < n ; k ++ ) { int T = arr1 [ i ] + arr2 [ j ] + arr3 [ k ] ; if ( isPresent ( arr4 , 0 , n - 1 , x - T ) ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int [ ] arr1 = { 1 , 4 , 5 , 6 } ; int [ ] arr2 = { 2 , 3 , 7 , 8 } ; int [ ] arr3 = { 1 , 4 , 6 , 10 } ; int [ ] arr4 = { 2 , 4 , 7 , 8 } ; int n = 4 ; int x = 30 ; System . out . println ( " Count ▁ = ▁ " + countQuadruples ( arr1 , arr2 , arr3 , arr4 , n , x ) ) ; } }

Index/key variables: i, j, k, mid
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
class GFG { static int countPairs ( int arr1 [ ] , int arr2 [ ] , int n , int value ) { int count = 0 ; int l = 0 , r = n - 1 ; while ( l < n & r >= 0 ) { int sum = arr1 [ l ] + arr2 [ r ] ; if ( sum == value ) { l ++ ; r -- ; count ++ ; } else if ( sum > value ) r -- ; else l ++ ; } return count ; } static int countQuadruples ( int arr1 [ ] , int arr2 [ ] , int arr3 [ ] , int arr4 [ ] , int n , int x ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) { int p_sum = arr1 [ i ] + arr2 [ j ] ; count += countPairs ( arr3 , arr4 , n , x - p_sum ) ; } return count ; } static public void main ( String [ ] args ) { int arr1 [ ] = { 1 , 4 , 5 , 6 } ; int arr2 [ ] = { 2 , 3 , 7 , 8 } ; int arr3 [ ] = { 1 , 4 , 6 , 10 } ; int arr4 [ ] = { 2 , 4 , 7 , 8 } ; int n = arr1 . length ; int x = 30 ; System . out . println ( " Count ▁ = ▁ " + countQuadruples ( arr1 , arr2 , arr3 , arr4 , n , x ) ) ; } }

Index/key variables: i, j, l, r
Accumulator variables: count, i, j, l, r
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countQuadruples ( int arr1 [ ] , int arr2 [ ] , int arr3 [ ] , int arr4 [ ] , int n , int x ) { int count = 0 ; Map < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( m . containsKey ( arr1 [ i ] + arr2 [ j ] ) ) m . put ( ( arr1 [ i ] + arr2 [ j ] ) , m . get ( ( arr1 [ i ] + arr2 [ j ] ) ) + 1 ) ; else m . put ( ( arr1 [ i ] + arr2 [ j ] ) , 1 ) ; for ( int k = 0 ; k < n ; k ++ ) for ( int l = 0 ; l < n ; l ++ ) { int p_sum = arr3 [ k ] + arr4 [ l ] ; if ( m . containsKey ( x - p_sum ) ) count += m . get ( x - p_sum ) ; } return count ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 1 , 4 , 5 , 6 } ; int arr2 [ ] = { 2 , 3 , 7 , 8 } ; int arr3 [ ] = { 1 , 4 , 6 , 10 } ; int arr4 [ ] = { 2 , 4 , 7 , 8 } ; int n = arr1 . length ; int x = 30 ; System . out . println ( " Count ▁ = ▁ " + countQuadruples ( arr1 , arr2 , arr3 , arr4 , n , x ) ) ; } }

Index/key variables: i, j, k, l
Accumulator variables: count, i, j, k, l
Iterator variables: i, j, k, l
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void main ( String [ ] args ) { int N = 4 , i , j , min ; System . out . println ( " Value ▁ of ▁ N : ▁ " + N ) ; for ( i = 1 ; i <= N ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { min = i < j ? i : j ; System . out . print ( N - min + 1 ) ; } System . out . println ( ) ; } } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class Solution { public static void main ( String [ ] args ) { int arr [ ] = { 10 , 2 , - 2 , - 20 , 10 } ; int k = - 10 ; int n = arr . length ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; for ( int j = i ; j < n ; j ++ ) { sum += arr [ j ] ; if ( sum == k ) res ++ ; } } System . out . println ( res ) ; } }

Index/key variables: j
Accumulator variables: i, j, res, sum
Iterator variables: i, j
Class/struct names: Solution
Java program:
import java . util . HashMap ; import java . util . Map ; public class GfG { static int findSubarraySum ( int arr [ ] , int n , int sum ) { HashMap < Integer , Integer > prevSum = new HashMap < > ( ) ; int res = 0 ; int currsum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { currsum += arr [ i ] ; if ( currsum == sum ) res ++ ; if ( prevSum . containsKey ( currsum - sum ) ) res += prevSum . get ( currsum - sum ) ; Integer count = prevSum . get ( currsum ) ; if ( count == null ) prevSum . put ( currsum , 1 ) ; else prevSum . put ( currsum , count + 1 ) ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 2 , - 2 , - 20 , 10 } ; int sum = - 10 ; int n = arr . length ; System . out . println ( findSubarraySum ( arr , n , sum ) ) ; } }

Index/key variables: i
Accumulator variables: currsum, i, res
Iterator variables: i
Class/struct names: GfG
Java program:
import java . io . * ; class GFG { static int countPairs ( int arr [ ] , int n ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int product = arr [ i ] * arr [ j ] ; for ( int k = 0 ; k < n ; k ++ ) { if ( arr [ k ] == product ) { result ++ ; break ; } } } } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 2 , 4 , 12 , 5 , 3 } ; int n = arr . length ; System . out . println ( countPairs ( arr , n ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k, result
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countPairs ( int arr [ ] , int n ) { int result = 0 ; HashSet < Integer > Hash = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { Hash . add ( arr [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int product = arr [ i ] * arr [ j ] ; if ( Hash . contains ( product ) ) { result ++ ; } } } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 2 , 4 , 12 , 5 , 3 } ; int n = arr . length ; System . out . println ( countPairs ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, result
Iterator variables: i, j
Class/struct names: GFG
Java program:
class clg { static int fib ( int n ) { if ( n <= 1 ) return n ; return fib ( n - 1 ) + fib ( n - 2 ) ; } public static void main ( String [ ] args ) { int n = 9 ; System . out . println ( fib ( n ) ) ; } }

Class/struct names: clg
Java program:
class GFG { static int factTR ( int n , int a ) { if ( n == 0 ) return a ; return factTR ( n - 1 , n * a ) ; } static int fact ( int n ) { return factTR ( n , 1 ) ; } static public void main ( String [ ] args ) { System . out . println ( fact ( 5 ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . Math ; import java . util . * ; class GFG { public static int [ ] minMaxRange ( int [ ] arr , int D , int N ) { int max = 1 , min = N ; for ( int i = 0 ; i < N ; i ++ ) { int dist = leftSearch ( arr , arr [ i ] - D , i ) ; min = Math . min ( min , dist ) ; max = Math . max ( max , dist ) ; dist = rightSearch ( arr , arr [ i ] + D , i ) ; min = Math . min ( min , dist ) ; max = Math . max ( max , dist ) ; } return new int [ ] { min , max } ; } public static int leftSearch ( int [ ] arr , int val , int i ) { if ( i == 0 ) return 1 ; int left = 0 , right = i - 1 ; int ind = - 1 ; while ( left <= right ) { int mid = ( left + right ) / 2 ; if ( arr [ mid ] < val ) { left = mid + 1 ; } else { right = mid - 1 ; ind = mid ; } } return ind != - 1 ? i - ind + 1 : 1 ; } public static int rightSearch ( int [ ] arr , int val , int i ) { if ( i == arr . length - 1 ) return 1 ; int left = i + 1 ; int right = arr . length - 1 ; int ind = - 1 ; while ( left <= right ) { int mid = ( left + right ) / 2 ; if ( arr [ mid ] > val ) { right = mid - 1 ; } else { left = mid + 1 ; ind = mid ; } } return ind != - 1 ? ind - i + 1 : 1 ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 5 , 9 , 14 } ; int N = arr . length ; int D = 4 ; int [ ] minMax = minMaxRange ( arr , D , N ) ; System . out . print ( minMax [ 0 ] + " ▁ " + minMax [ 1 ] ) ; } }

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void findPairs ( int arr1 [ ] , int arr2 [ ] , int n , int m , int x ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( arr1 [ i ] + arr2 [ j ] == x ) System . out . println ( arr1 [ i ] + " ▁ " + arr2 [ j ] ) ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 1 , 2 , 3 , 7 , 5 , 4 } ; int arr2 [ ] = { 0 , 7 , 4 , 3 , 2 , 1 } ; int x = 8 ; findPairs ( arr1 , arr2 , arr1 . length , arr2 . length , x ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void findPairs ( int arr1 [ ] , int arr2 [ ] , int n , int m , int x ) { HashMap < Integer , Integer > s = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) s . put ( arr1 [ i ] , 0 ) ; for ( int j = 0 ; j < m ; j ++ ) if ( s . containsKey ( x - arr2 [ j ] ) ) System . out . println ( x - arr2 [ j ] + " ▁ " + arr2 [ j ] ) ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 1 , 0 , - 4 , 7 , 6 , 4 } ; int arr2 [ ] = { 0 , 2 , 4 , - 3 , 2 , 1 } ; int x = 8 ; findPairs ( arr1 , arr2 , arr1 . length , arr2 . length , x ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int largestAltitude ( int L , int B ) { if ( L > B ) { int t = L ; L = B ; B = t ; } int res = Math . min ( B / 2 , L ) ; return res ; } public static void main ( String [ ] args ) { int L = 3 ; int B = 4 ; System . out . print ( largestAltitude ( L , B ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static class Node { int key ; Node left , right ; Node ( int key ) { left = null ; right = null ; this . key = key ; } } static class INT { static int d ; INT ( ) { d = 0 ; } } static boolean isBalancedUtil ( Node root , INT maxh , INT minh ) { if ( root == null ) { maxh . d = minh . d = 0 ; return true ; } INT lmxh = new INT ( ) , lmnh = new INT ( ) ; INT rmxh = new INT ( ) , rmnh = new INT ( ) ; if ( isBalancedUtil ( root . left , lmxh , lmnh ) == false ) return false ; if ( isBalancedUtil ( root . right , rmxh , rmnh ) == false ) return false ; maxh . d = Math . max ( lmxh . d , rmxh . d ) + 1 ; minh . d = Math . min ( lmnh . d , rmnh . d ) + 1 ; if ( maxh . d <= 2 * minh . d ) return true ; return false ; } static boolean isBalanced ( Node root ) { INT maxh = new INT ( ) , minh = new INT ( ) ; return isBalancedUtil ( root , maxh , minh ) ; } public static void main ( String args [ ] ) { Node root = new Node ( 10 ) ; root . left = new Node ( 5 ) ; root . right = new Node ( 100 ) ; root . right . left = new Node ( 50 ) ; root . right . right = new Node ( 150 ) ; root . right . left . left = new Node ( 40 ) ; System . out . println ( isBalanced ( root ) ? " Balanced " : " Not ▁ Balanced " ) ; } }

Class/struct names: GFG, INT, Node
Java program:
import java . io . * ; class GFG { static void findLargestIndex ( int arr [ ] , int n ) { for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( arr [ i ] == i ) { System . out . println ( i ) ; return ; } } System . out . println ( - 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 10 , - 5 , 0 , 3 , 7 } ; int n = arr . length ; findLargestIndex ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void countFreq ( int a [ ] , int n ) { int hm [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) hm [ a [ i ] ] ++ ; int cumul = 0 ; for ( int i = 0 ; i < n ; i ++ ) { cumul += hm [ a [ i ] ] ; if ( hm [ a [ i ] ] != 0 ) { System . out . println ( a [ i ] + " - > " + cumul ) ; } hm [ a [ i ] ] = 0 ; } } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 2 , 4 , 2 , 1 } ; int n = a . length ; countFreq ( a , n ) ; } }

Index/key variables: i, n
Accumulator variables: cumul, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; public class GFG { static void findPair ( int [ ] arr , int n ) { boolean found = false ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { for ( int k = 0 ; k < n ; k ++ ) { if ( arr [ i ] + arr [ j ] == arr [ k ] ) { System . out . println ( arr [ i ] + " ▁ " + arr [ j ] ) ; found = true ; } } } } if ( found == false ) System . out . println ( " Not ▁ exist " ) ; } static public void main ( String [ ] args ) { int [ ] arr = { 10 , 4 , 8 , 13 , 5 } ; int n = arr . length ; findPair ( arr , n ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Boolean variables: found
Class/struct names: GFG
Java program:
class GFG { static boolean check ( int n , int m , int x , int y , int vl ) { int temp = m ; if ( vl > n ) return false ; int ex = n - vl ; ex *= y ; temp += ex ; int cr = temp / x ; if ( cr >= vl ) return true ; return false ; } static int maximizeMangoes ( int n , int m , int x , int y ) { int l = 0 , r = n ; int ans = 0 ; while ( l <= r ) { int mid = l + ( r - l ) / 2 ; if ( check ( n , m , x , y , mid ) ) { ans = mid ; l = mid + 1 ; } else r = mid - 1 ; } return ans ; } public static void main ( String [ ] args ) { int W = 4 , C = 8 , x = 4 , y = 4 ; System . out . println ( maximizeMangoes ( W , C , x , y ) ) ; } }

Accumulator variables: ex, temp
Class/struct names: GFG
Java program:
class GFG { public static int findkthElement ( int arr [ ] , int n , int K ) { int l = 0 ; int h = n - 1 , r ; while ( l + 1 < h ) { int mid = ( l + h ) / 2 ; if ( arr [ l ] >= arr [ mid ] ) l = mid ; else h = mid ; } if ( arr [ l ] < arr [ h ] ) r = l ; else r = h ; if ( K <= r + 1 ) return arr [ r + 1 - K ] ; else return arr [ n - ( K - ( r + 1 ) ) ] ; } public static void main ( String args [ ] ) { int [ ] arr = { 10 , 8 , 6 , 5 , 2 , 1 , 13 , 12 } ; int n = arr . length ; int K = 3 ; System . out . println ( findkthElement ( arr , n , K ) ) ; } }

Index/key variables: h, l, mid
Class/struct names: GFG