dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { static class Node { int data ; Node left , right ; Node ( int key ) { data = key ; left = null ; right = null ; } } static int maxLevel = - 1 ; static int res = - 1 ; static void find ( Node root , int level ) { if ( root != null ) { find ( root . left , ++ level ) ; if ( level > maxLevel ) { res = root . data ; maxLevel = level ; } find ( root . right , level ) ; } } static int deepestNode ( Node root ) { int res = - 1 ; int maxLevel = - 1 ; find ( root , 0 ) ; return res ; } public static void main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . right . left = new Node ( 5 ) ; root . right . right = new Node ( 6 ) ; root . right . left . right = new Node ( 7 ) ; root . right . right . right = new Node ( 8 ) ; root . right . left . right . left = new Node ( 9 ) ; System . out . println ( deepestNode ( root ) ) ; } }

Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static void iskPalindromesPossible ( String s , int k ) { if ( s . length ( ) < k ) { System . out . print ( " Not ▁ Possible " + "NEW_LINE"); return ; } if ( s . length ( ) == k ) { System . out . print ( " Possible " + "NEW_LINE"); return ; } HashMap < Character , Integer > freq = new HashMap < Character , Integer > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) if ( freq . containsKey ( s . charAt ( i ) ) ) { freq . put ( s . charAt ( i ) , freq . get ( s . charAt ( i ) ) + 1 ) ; } else { freq . put ( s . charAt ( i ) , 1 ) ; } int count = 0 ; for ( Map . Entry < Character , Integer > it : freq . entrySet ( ) ) { if ( it . getValue ( ) % 2 == 1 ) count ++ ; } if ( count > k ) System . out . print ( " No " + "NEW_LINE"); else System . out . print ( " Yes " + "NEW_LINE"); } public static void main ( String [ ] args ) { String str = " poor " ; int K = 3 ; iskPalindromesPossible ( str , K ) ; str = " geeksforgeeks " ; K = 10 ; iskPalindromesPossible ( str , K ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static class Node { int data ; Node left , right ; Node ( int key ) { data = key ; left = null ; right = null ; } } ; static int height ( Node root ) { if ( root == null ) return 0 ; int leftHt = height ( root . left ) ; int rightHt = height ( root . right ) ; return Math . max ( leftHt , rightHt ) + 1 ; } static void deepestNode ( Node root , int levels ) { if ( root == null ) return ; if ( levels == 1 ) System . out . print ( root . data + " ▁ " ) ; else if ( levels > 1 ) { deepestNode ( root . left , levels - 1 ) ; deepestNode ( root . right , levels - 1 ) ; } } public static void main ( String args [ ] ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . right . left = new Node ( 5 ) ; root . right . right = new Node ( 6 ) ; root . right . left . right = new Node ( 7 ) ; root . right . right . right = new Node ( 8 ) ; root . right . left . right . left = new Node ( 9 ) ; int levels = height ( root ) ; deepestNode ( root , levels ) ; } }

Class/struct names: GFG, Node
Java program:
class GFG { static int findPivot ( int arr [ ] , int low , int high ) { if ( high < low ) return - 1 ; if ( high == low ) return low ; int mid = ( low + high ) / 2 ; if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) { return mid ; } if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) { return mid - 1 ; } if ( arr [ low ] > arr [ mid ] ) { return findPivot ( arr , low , mid - 1 ) ; } else { return findPivot ( arr , mid + 1 , high ) ; } } public static boolean isRotated ( int arr [ ] , int n ) { int l = 0 ; int r = n - 1 ; int pivot = - 1 ; if ( arr [ l ] > arr [ r ] ) { pivot = findPivot ( arr , l , r ) ; int temp = pivot ; if ( l < pivot ) { while ( pivot > l ) { if ( arr [ pivot ] < arr [ pivot - 1 ] ) { return false ; } pivot -- ; } } pivot = temp ; else { pivot ++ ; while ( pivot < r ) { if ( arr [ pivot ] > arr [ pivot + 1 ] ) { return false ; } pivot ++ ; } } return true ; } else { return false ; } } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 1 , 3 , 2 } ; System . out . println ( isRotated ( arr , 5 ) ) ; } }

Index/key variables: l, low, mid, pivot, r
Accumulator variables: pivot
Class/struct names: GFG
Java program:
import java . util . * ; public class Node { int data ; Node left , right ; Node ( int key ) { data = key ; left = null ; right = null ; } } ; class Gfg { public static Node deepestNode ( Node root ) { Node tmp = null ; if ( root == null ) return null ; Queue < Node > q = new LinkedList < Node > ( ) ; q . offer ( root ) ; while ( ! q . isEmpty ( ) ) { tmp = q . poll ( ) ; if ( tmp . left != null ) q . offer ( tmp . left ) ; if ( tmp . right != null ) q . offer ( tmp . right ) ; } return tmp ; } public static void main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . right . left = new Node ( 5 ) ; root . right . right = new Node ( 6 ) ; root . right . left . right = new Node ( 7 ) ; root . right . right . right = new Node ( 8 ) ; root . right . left . right . left = new Node ( 9 ) ; Node deepNode = deepestNode ( root ) ; System . out . println ( deepNode . data ) ; } }

Class/struct names: Gfg, Node
Java program:
class GFG { static void findpair ( int l , int r ) { int ans1 = l ; int ans2 = 2 * l ; System . out . println ( ans1 + " , ▁ " + ans2 ) ; } public static void main ( String args [ ] ) { int l = 1 , r = 10 ; findpair ( l , r ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Student { String name ; int marks , prev_rank ; Student ( ) { this . marks = 0 ; this . prev_rank = 0 ; } } static void nameRank ( String [ ] names , int [ ] marks , int [ ] updates , int n ) { Student [ ] x = new Student [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = new Student ( ) ; x [ i ] . name = names [ i ] ; x [ i ] . marks = marks [ i ] + updates [ i ] ; x [ i ] . prev_rank = i + 1 ; } Student highest = x [ 0 ] ; for ( int j = 1 ; j < n ; j ++ ) { if ( x [ j ] . marks >= highest . marks ) highest = x [ j ] ; } System . out . print ( " Name : ▁ " + highest . name + " , ▁ Jump : ▁ " + Math . abs ( highest . prev_rank - 1 ) ) ; } public static void main ( String [ ] args ) { String [ ] names = { " sam " , " ram " , " geek " } ; int [ ] marks = { 80 , 79 , 75 } ; int [ ] updates = { 0 , 5 , - 9 } ; int n = marks . length ; nameRank ( names , marks , updates , n ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, Student
Java program:
import java . io . * ; class GFG { static int countDigits ( int n ) { int count = 0 ; while ( n > 0 ) { count += 1 ; n /= 10 ; } return count ; } static int getDistinct ( int d , int count ) { int num = 0 ; count = ( int ) Math . pow ( 10 , count - 1 ) ; while ( count > 0 ) { num += ( count * d ) ; count /= 10 ; } return num ; } static int findCount ( int L , int R ) { int count = 0 ; int countDigitsL = countDigits ( L ) ; int countDigitsR = countDigits ( R ) ; int firstDigitL = ( L / ( int ) Math . pow ( 10 , countDigitsL - 1 ) ) ; int firstDigitR = ( R / ( int ) Math . pow ( 10 , countDigitsR - 1 ) ) ; if ( countDigitsL < countDigitsR ) { count += ( 9 * ( countDigitsR - countDigitsL - 1 ) ) ; if ( getDistinct ( firstDigitL , countDigitsL ) >= L ) count += ( 9 - firstDigitL + 1 ) ; else count += ( 9 - firstDigitL ) ; if ( getDistinct ( firstDigitR , countDigitsR ) <= R ) count += firstDigitR ; else count += ( firstDigitR - 1 ) ; } else { if ( getDistinct ( firstDigitL , countDigitsL ) >= L ) count += ( 9 - firstDigitL + 1 ) ; else count += ( 9 - firstDigitL ) ; if ( getDistinct ( firstDigitR , countDigitsR ) <= R ) count -= ( 9 - firstDigitR ) ; else count -= ( 9 - firstDigitR + 1 ) ; } return count ; } public static void main ( String [ ] args ) { int L = 10 , R = 50 ; System . out . println ( findCount ( L , R ) ) ; } }

Accumulator variables: count, n, num
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int N = 4 ; static final int M = 4 ; static boolean isPairWithDiff ( int mat [ ] [ ] , int k ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] > k ) { int m = mat [ i ] [ j ] - k ; if ( s . contains ( m ) ) { return true ; } } else { int m = k - mat [ i ] [ j ] ; if ( s . contains ( m ) ) { return true ; } } s . add ( mat [ i ] [ j ] ) ; } } return false ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 5 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 100 } } ; int k = 85 ; System . out . println ( isPairWithDiff ( mat , k ) == true ? " YES " : " NO " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { public static void printNSE ( int arr [ ] , int n ) { Stack < Integer > s = new Stack < Integer > ( ) ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; s . push ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . empty ( ) ) { s . push ( arr [ i ] ) ; continue ; } while ( s . empty ( ) == false && s . peek ( ) > arr [ i ] ) { mp . put ( s . peek ( ) , arr [ i ] ) ; s . pop ( ) ; } s . push ( arr [ i ] ) ; } while ( s . empty ( ) == false ) { mp . put ( s . peek ( ) , - 1 ) ; s . pop ( ) ; } for ( int i = 0 ; i < n ; i ++ ) System . out . println ( arr [ i ] + " ▁ - - - > ▁ " + mp . get ( arr [ i ] ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 11 , 13 , 21 , 3 } ; int n = arr . length ; printNSE ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static Node getDeepestLeftLeafNode ( Node root ) { if ( root == null ) return null ; Queue < Node > q = new LinkedList < > ( ) ; q . add ( root ) ; Node result = null ; while ( ! q . isEmpty ( ) ) { Node temp = q . peek ( ) ; q . remove ( ) ; if ( temp . left != null ) { q . add ( temp . left ) ; if ( temp . left . left == null && temp . left . right == null ) result = temp . left ; } if ( temp . right != null ) q . add ( temp . right ) ; } return result ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; root . right . left . right = newNode ( 7 ) ; root . right . right . right = newNode ( 8 ) ; root . right . left . right . left = newNode ( 9 ) ; root . right . right . right . right = newNode ( 10 ) ; Node result = getDeepestLeftLeafNode ( root ) ; if ( result != null ) System . out . println ( " Deepest ▁ Left ▁ Leaf ▁ Node ▁ : : ▁ " + result . data ) ; else System . out . println ( " No ▁ result , ▁ " + " left ▁ leaf ▁ not ▁ found " ) ; } }

Class/struct names: GFG, Node
Java program:
import java . util . Vector ; class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = null ; right = null ; } } class BinaryTree { Node root ; void preOrder ( Node node ) { if ( node != null ) { System . out . print ( node . data + " ▁ " ) ; preOrder ( node . left ) ; preOrder ( node . right ) ; } } Vector < Node > getTrees ( int arr [ ] , int start , int end ) { Vector < Node > trees = new Vector < Node > ( ) ; if ( start > end ) { trees . add ( null ) ; return trees ; } for ( int i = start ; i <= end ; i ++ ) { Vector < Node > ltrees = getTrees ( arr , start , i - 1 ) ; Vector < Node > rtrees = getTrees ( arr , i + 1 , end ) ; for ( int j = 0 ; j < ltrees . size ( ) ; j ++ ) { for ( int k = 0 ; k < rtrees . size ( ) ; k ++ ) { Node node = new Node ( arr [ i ] ) ; node . left = ltrees . get ( j ) ; node . right = rtrees . get ( k ) ; trees . add ( node ) ; } } } return trees ; } public static void main ( String args [ ] ) { int in [ ] = { 4 , 5 , 7 } ; int n = in . length ; BinaryTree tree = new BinaryTree ( ) ; Vector < Node > trees = tree . getTrees ( in , 0 , n - 1 ) ; System . out . println ( " Preorder ▁ traversal ▁ of ▁ different ▁ " + " ▁ binary ▁ trees ▁ are : " ) ; for ( int i = 0 ; i < trees . size ( ) ; i ++ ) { tree . preOrder ( trees . get ( i ) ) ; System . out . println ( " " ) ; } } }

Index/key variables: i
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: BinaryTree, Node
Java program:
class GFG { public static void main ( String [ ] args ) { String s1 = " geeks " , s2 = " geeksforgeeks " ; boolean result = s2 . endsWith ( s1 ) ; if ( result ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Class/struct names: GFG
Java program:
import java . util . Arrays ; public class GFG { static boolean ElementsCalculationFunc ( int pre [ ] , int maxx [ ] , int x , int k , int n ) { for ( int i = 0 , j = x ; j <= n ; j ++ , i ++ ) { if ( x * maxx [ j ] - ( pre [ j ] - pre [ i ] ) <= k ) return true ; } return false ; } static void MaxNumberOfElements ( int a [ ] , int n , int k ) { Arrays . sort ( a ) ; for ( int i = 0 ; i <= n ; ++ i ) { pre [ i ] = 0 ; maxx [ i ] = 0 ; } for ( int i = 1 ; i <= n ; i ++ ) { pre [ i ] = pre [ i - 1 ] + a [ i - 1 ] ; maxx [ i ] = Math . max ( maxx [ i - 1 ] , a [ i - 1 ] ) ; } int l = 1 , r = n , ans = 0 ; while ( l < r ) { int mid = ( l + r ) / 2 ; if ( ElementsCalculationFunc ( pre , maxx , mid - 1 , k , n ) ) { ans = mid ; l = mid + 1 ; } else r = mid - 1 ; } System . out . print ( ( int ) ans + "NEW_LINE"); } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 4 , 9 } ; int n = arr . length ; int k = 3 ; MaxNumberOfElements ( arr , n , k ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int MAX_STR_LEN = 1000 ; static boolean P [ ] [ ] = new boolean [ MAX_STR_LEN ] [ MAX_STR_LEN ] ; static int [ ] Kpal = new int [ MAX_STR_LEN ] ; static void checkSubStrPal ( String str , int n ) { for ( int i = 0 ; i < MAX_STR_LEN ; i ++ ) { for ( int j = 0 ; j < MAX_STR_LEN ; j ++ ) P [ i ] [ j ] = false ; Kpal [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) P [ i ] [ i ] = true ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( str . charAt ( i ) == str . charAt ( i + 1 ) ) P [ i ] [ i + 1 ] = true ; for ( int gap = 2 ; gap < n ; gap ++ ) { for ( int i = 0 ; i < n - gap ; i ++ ) { int j = gap + i ; if ( str . charAt ( i ) == str . charAt ( j ) && P [ i + 1 ] [ j - 1 ] ) P [ i ] [ j ] = true ; } } } static void countKPalindromes ( int i , int j , int k ) { if ( i == j ) { Kpal [ k ] ++ ; return ; } if ( P [ i ] [ j ] == false ) return ; Kpal [ k ] ++ ; int mid = ( i + j ) / 2 ; if ( ( j - i + 1 ) % 2 == 1 ) mid -- ; countKPalindromes ( i , mid , k + 1 ) ; } static void printKPalindromes ( String s ) { int n = s . length ( ) ; checkSubStrPal ( s , n ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n - i ; j ++ ) countKPalindromes ( j , j + i , 1 ) ; for ( int i = 1 ; i <= n ; i ++ ) System . out . print ( Kpal [ i ] + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String args [ ] ) { String s = " abacaba " ; printKPalindromes ( s ) ; } }

Index/key variables: MAX_STR_LEN, i, j, k
Accumulator variables: gap, i, j, mid
Iterator variables: gap, i, j
Class/struct names: GFG
Java program:
import java . io . FileNotFoundException ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Iterator ; class GFG { private static String printNumbers ( int [ ] numbers ) { ArrayList < Integer > array = new ArrayList < > ( ) ; for ( int number : numbers ) { if ( findContainsOneTwoThree ( number ) ) array . add ( number ) ; } Collections . sort ( array ) ; StringBuffer strbuf = new StringBuffer ( ) ; Iterator it = array . iterator ( ) ; while ( it . hasNext ( ) ) { int value = ( int ) it . next ( ) ; if ( strbuf . length ( ) > 0 ) strbuf . append ( " , ▁ " ) ; strbuf . append ( Integer . toString ( value ) ) ; } return ( strbuf . length ( ) > 0 ) ? strbuf . toString ( ) : " - 1" ; } private static boolean findContainsOneTwoThree ( int number ) { String str = Integer . toString ( number ) ; return ( str . contains ( "1" ) && str . contains ( "2" ) && str . contains ( "3" ) ) ; } public static void main ( String [ ] args ) { int [ ] numbers = { 123 , 1232 , 456 , 234 , 32145 } ; System . out . println ( printNumbers ( numbers ) ) ; } }

Iterator variables: number
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Interval { int s ; int e ; Interval ( int a , int b ) { s = a ; e = b ; } } ; static class Sortby implements Comparator < Interval > { public int compare ( Interval a , Interval b ) { return a . s - b . s ; } } static int kthSmallestNum ( Vector < Interval > merged , int k ) { int n = merged . size ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( k <= Math . abs ( merged . get ( j ) . e - merged . get ( j ) . s + 1 ) ) return ( merged . get ( j ) . s + k - 1 ) ; k = k - Math . abs ( merged . get ( j ) . e - merged . get ( j ) . s + 1 ) ; } if ( k != 0 ) return - 1 ; return 0 ; } static Vector < Interval > mergeIntervals ( Vector < Interval > merged , Interval arr [ ] , int n ) { Arrays . sort ( arr , new Sortby ( ) ) ; merged . add ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { Interval prev = merged . get ( merged . size ( ) - 1 ) ; Interval curr = arr [ i ] ; if ( ( curr . s >= prev . s && curr . s <= prev . e ) && ( curr . e > prev . e ) ) merged . get ( merged . size ( ) - 1 ) . e = curr . e ; else { merged . add ( curr ) ; } } return merged ; } public static void main ( String args [ ] ) { Interval arr [ ] = { new Interval ( 2 , 6 ) , new Interval ( 4 , 7 ) } ; int n = arr . length ; int query [ ] = { 5 , 8 } ; int q = query . length ; Vector < Interval > merged = new Vector < Interval > ( ) ; merged = mergeIntervals ( merged , arr , n ) ; for ( int i = 0 ; i < q ; i ++ ) System . out . println ( kthSmallestNum ( merged , query [ i ] ) ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, Interval, Sortby
Java program:
class Country { public static void countCountries ( int ans [ ] , int N ) { int total_countries = 0 , i = 0 ; boolean invalid = false ; while ( i < N ) { int curr_size = ans [ i ] ; int num = ans [ i ] ; while ( num > 0 ) { if ( ans [ i ] != curr_size ) { System . out . print ( "Invalid AnswerNEW_LINE" ); return ; } else num -- ; i ++ ; } total_countries ++ ; } System . out . print ( " There ▁ are ▁ " + total_countries + " distinct companies in the group.NEW_LINE" ); } public static void main ( String [ ] args ) { int ans [ ] = { 1 , 1 , 2 , 2 , 4 , 4 , 4 , 4 } ; int n = 8 ; countCountries ( ans , n ) ; } }

Index/key variables: i
Accumulator variables: i, num, total_countries
Boolean variables: invalid
Class/struct names: Country
Java program:
class Node { int data ; Node left , right ; public Node ( int data ) { this . data = data ; left = right = null ; } } class Level { int maxlevel = 0 ; } class BinaryTree { Node root ; Node result ; void deepestLeftLeafUtil ( Node node , int lvl , Level level , boolean isLeft ) { if ( node == null ) return ; if ( isLeft != false && node . left == null && node . right == null && lvl > level . maxlevel ) { result = node ; level . maxlevel = lvl ; } deepestLeftLeafUtil ( node . left , lvl + 1 , level , true ) ; deepestLeftLeafUtil ( node . right , lvl + 1 , level , false ) ; } void deepestLeftLeaf ( Node node ) { Level level = new Level ( ) ; deepestLeftLeafUtil ( node , 0 , level , false ) ; } 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 . right . left = new Node ( 5 ) ; tree . root . right . right = new Node ( 6 ) ; tree . root . right . left . right = new Node ( 7 ) ; tree . root . right . right . right = new Node ( 8 ) ; tree . root . right . left . right . left = new Node ( 9 ) ; tree . root . right . right . right . right = new Node ( 10 ) ; tree . deepestLeftLeaf ( tree . root ) ; if ( tree . result != null ) System . out . println ( " The ▁ deepest ▁ left ▁ child " + " ▁ is ▁ " + tree . result . data ) ; else System . out . println ( " There ▁ is ▁ no ▁ left ▁ leaf ▁ in " + " ▁ the ▁ given ▁ tree " ) ; } }

Class/struct names: BinaryTree, Level, Node
Java program:
import java . util . * ; class GFG { public static boolean check_elements ( int arr [ ] , int n , int A , int B ) { int range = B - A ; for ( int i = 0 ; i < n ; i ++ ) { if ( Math . abs ( arr [ i ] ) >= A && Math . abs ( arr [ i ] ) <= B ) { int z = Math . abs ( arr [ i ] ) - A ; if ( arr [ z ] > 0 ) { arr [ z ] = arr [ z ] * - 1 ; } } } int count = 0 ; for ( int i = 0 ; i <= range && i < n ; i ++ ) { if ( arr [ i ] > 0 ) return false ; else count ++ ; } if ( count != ( range + 1 ) ) return false ; return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 5 , 2 , 7 , 8 , 3 } ; int n = arr . length ; int A = 2 , B = 5 ; if ( check_elements ( arr , n , A , B ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, z
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int findMinRec ( int A [ ] , int n ) { if ( n == 1 ) return A [ 0 ] ; return Math . min ( A [ n - 1 ] , findMinRec ( A , n - 1 ) ) ; } public static void main ( String args [ ] ) { int A [ ] = { 1 , 4 , 45 , 6 , - 50 , 10 , 2 } ; int n = A . length ; System . out . println ( findMinRec ( A , n ) ) ; } }

Class/struct names: GFG
Java program:
public class GFG { static boolean isPossible ( int arr [ ] , int n , int m , int curr_min ) { int studentsRequired = 1 ; int curr_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > curr_min ) return false ; if ( curr_sum + arr [ i ] > curr_min ) { studentsRequired ++ ; curr_sum = arr [ i ] ; if ( studentsRequired > m ) return false ; } else curr_sum += arr [ i ] ; } return true ; } static int findPages ( int arr [ ] , int n , int m ) { long sum = 0 ; if ( n < m ) return - 1 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; int start = 0 , end = ( int ) sum ; int result = Integer . MAX_VALUE ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( isPossible ( arr , n , m , mid ) ) { result = mid ; end = mid - 1 ; } else start = mid + 1 ; } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 34 , 67 , 90 } ; System . out . println ( " Minimum ▁ number ▁ of ▁ pages ▁ = ▁ " + findPages ( arr , arr . length , m ) ) ; } }

Index/key variables: i
Accumulator variables: curr_sum, i, studentsRequired, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void maximizeSum ( int arr [ ] , int n , int k ) { int cnt [ ] = new int [ 30 ] ; int X = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 30 ; j ++ ) { if ( ( arr [ i ] & ( 1 << j ) ) != 0 ) cnt [ j ] ++ ; } } ArrayList < int [ ] > v = new ArrayList < > ( ) ; for ( int i = 0 ; i < 30 ; i ++ ) { int gain = cnt [ i ] * ( 1 << i ) ; v . add ( new int [ ] { i , gain } ) ; } Collections . sort ( v , ( a , b ) -> { if ( a [ 1 ] != b [ 1 ] ) return b [ 1 ] - a [ 1 ] ; return a [ 0 ] - b [ 0 ] ; } ) ; for ( int i = 0 ; i < k ; i ++ ) { X |= ( 1 << v . get ( i ) [ 0 ] ) ; } System . out . println ( X ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 5 , 1 } ; int K = 1 ; int N = arr . length ; maximizeSum ( arr , N , K ) ; } }

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