dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GfG { static class Node { int data ; Node left ; Node right ; } static int heightOfTreeUtil ( Node root , boolean isEven ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) { if ( isEven == true ) return 1 ; else return 0 ; } int left = heightOfTreeUtil ( root . left , ! isEven ) ; int right = heightOfTreeUtil ( root . right , ! isEven ) ; if ( left == 0 && right == 0 ) return 0 ; return ( 1 + Math . max ( left , right ) ) ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } static int heightOfTree ( Node root ) { return heightOfTreeUtil ( root , false ) ; } 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 ) ; root . left . right . left = newNode ( 6 ) ; System . out . println ( " Height ▁ of ▁ tree ▁ is ▁ " + heightOfTree ( root ) ) ; } }

Class/struct names: GfG, Node
Java program:
class BinaryTree { void fillDepth ( int parent [ ] , int i , int depth [ ] ) { if ( depth [ i ] != 0 ) { return ; } if ( parent [ i ] == - 1 ) { depth [ i ] = 1 ; return ; } if ( depth [ parent [ i ] ] == 0 ) { fillDepth ( parent , parent [ i ] , depth ) ; } depth [ i ] = depth [ parent [ i ] ] + 1 ; } int findHeight ( int parent [ ] , int n ) { int depth [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { depth [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { fillDepth ( parent , i , depth ) ; } int ht = depth [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( ht < depth [ i ] ) { ht = depth [ i ] ; } } return ht ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; int parent [ ] = new int [ ] { - 1 , 0 , 0 , 1 , 1 , 3 , 5 } ; int n = parent . length ; System . out . println ( " Height ▁ is ▁ " + tree . findHeight ( parent , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: BinaryTree
Java program:
class Node { int data ; Node left , right ; Node ( int d ) { data = d ; left = right = null ; } } class BinaryTree { Node root ; boolean isBalanced ( Node node ) { int lh ; int rh ; if ( node == null ) return true ; lh = height ( node . left ) ; rh = height ( node . right ) ; if ( Math . abs ( lh - rh ) <= 1 && isBalanced ( node . left ) && isBalanced ( node . right ) ) return true ; return false ; } int height ( Node node ) { if ( node == null ) return 0 ; return 1 + Math . max ( height ( node . left ) , height ( node . right ) ) ; } 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 . left . left . left = new Node ( 8 ) ; if ( tree . isBalanced ( tree . root ) ) System . out . println ( " Tree ▁ is ▁ balanced " ) ; else System . out . println ( " Tree ▁ is ▁ not ▁ balanced " ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . io . * ; import java . util . * ; class Node { int data ; Node left , right ; Node ( int key ) { data = key ; left = right = null ; } } class GFG { static boolean isLeaf ( Node node ) { return ( node . left != null && node . left . right == node && node . right != null && node . right . left == node ) ; } static int maxDepth ( Node node ) { if ( node == null ) return 0 ; if ( isLeaf ( node ) ) return 1 ; return 1 + Math . max ( maxDepth ( node . left ) , maxDepth ( node . right ) ) ; } 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 . left . right = new Node ( 5 ) ; root . left . left . left = new Node ( 6 ) ; Node L1 = root . left . left . left ; Node L2 = root . left . right ; Node L3 = root . right ; L1 . right = L2 ; L2 . right = L3 ; L3 . right = L1 ; L3 . left = L2 ; L2 . left = L1 ; L1 . left = L3 ; System . out . println ( " Height ▁ of ▁ tree ▁ is ▁ " + maxDepth ( root ) ) ; } }

Class/struct names: GFG, Node
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; static int height ( Node node ) { if ( node == null ) return 0 ; return ( 1 + Math . max ( height ( node . left ) , height ( node . right ) ) ) ; } int diameter ( Node root ) { if ( root == null ) return 0 ; int lheight = height ( root . left ) ; int rheight = height ( root . right ) ; int ldiameter = diameter ( root . left ) ; int rdiameter = diameter ( root . right ) ; return Math . max ( lheight + rheight + 1 , Math . max ( ldiameter , rdiameter ) ) ; } int diameter ( ) { return diameter ( root ) ; } 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 ▁ diameter ▁ of ▁ given ▁ binary ▁ tree ▁ is ▁ : ▁ " + tree . diameter ( ) ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . io . * ; class GFG { static void findpath ( int N , int a [ ] ) { if ( a [ 0 ] == 1 ) { System . out . print ( ( N + 1 ) + " ▁ " ) ; for ( int i = 1 ; i <= N ; i ++ ) System . out . print ( ( i ) + " ▁ " ) ; return ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( a [ i ] == 0 && a [ i + 1 ] == 1 ) { for ( int j = 1 ; j <= i ; j ++ ) System . out . print ( ( j ) + " ▁ " ) ; System . out . print ( ( N + 1 ) + " ▁ " ) ; for ( int j = i + 1 ; j <= N ; j ++ ) System . out . print ( ( j ) + " ▁ " ) ; return ; } } for ( int i = 1 ; i <= N ; i ++ ) System . out . print ( ( i ) + " ▁ " ) ; System . out . print ( ( N + 1 ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int N = 3 , arr [ ] = { 0 , 1 , 0 } ; int N = 3 , arr [ ] = { 0 , 1 , 0 } ; findpath ( N , arr ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void balBracketSequence ( String str ) { int n = str . length ( ) ; if ( str . charAt ( 0 ) == str . charAt ( n - 1 ) ) { System . out . println ( " No " ) ; } else { int cntForOpen = 0 , cntForClose = 0 ; int check = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( 0 ) ) cntForOpen ++ ; else if ( str . charAt ( i ) == str . charAt ( n - 1 ) ) cntForOpen -= 1 ; else cntForOpen += 1 ; if ( cntForOpen < 0 ) { check = 0 ; break ; } } if ( check != 0 && cntForOpen == 0 ) { System . out . print ( " Yes , ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( n - 1 ) ) System . out . print ( ' ) ' ) ; else System . out . print ( ' ( ' ) ; } return ; } else { for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( 0 ) ) cntForClose ++ ; else cntForClose -- ; if ( cntForClose < 0 ) { check = 0 ; break ; } } if ( check != 0 && cntForClose == 0 ) { System . out . print ( " Yes , ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) == str . charAt ( 0 ) ) System . out . print ( ' ( ' ) ; else System . out . print ( ' ) ' ) ; } return ; } } System . out . print ( " No " ) ; } } public static void main ( String args [ ] ) { String str = "123122" ; balBracketSequence ( str ) ; } }

Accumulator variables: cntForClose, cntForOpen, 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 ; } } class Height { int h ; } class BinaryTree { Node root ; int diameterOpt ( Node root , Height height ) { Height lh = new Height ( ) , rh = new Height ( ) ; if ( root == null ) { height . h = 0 ; return 0 ; } int ldiameter = diameterOpt ( root . left , lh ) ; int rdiameter = diameterOpt ( root . right , rh ) ; height . h = Math . max ( lh . h , rh . h ) + 1 ; return Math . max ( lh . h + rh . h + 1 , Math . max ( ldiameter , rdiameter ) ) ; } int diameter ( ) { Height height = new Height ( ) ; return diameterOpt ( root , height ) ; } static int height ( Node node ) { if ( node == null ) return 0 ; return ( 1 + Math . max ( height ( node . left ) , height ( node . right ) ) ) ; } 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 ▁ diameter ▁ of ▁ given ▁ binary ▁ tree ▁ is ▁ : ▁ " + tree . diameter ( ) ) ; } }

Class/struct names: BinaryTree, Height, Node
Java program:
class GfG { static class Node { int data ; Node left , right ; } static class A { int ans = Integer . MIN_VALUE ; } static int height ( Node root , A a ) { if ( root == null ) return 0 ; int left_height = height ( root . left , a ) ; int right_height = height ( root . right , a ) ; a . ans = Math . max ( a . ans , 1 + left_height + right_height ) ; return 1 + Math . max ( left_height , right_height ) ; } static int diameter ( Node root ) { if ( root == null ) return 0 ; A a = new A ( ) ; int height_of_tree = height ( root , a ) ; return a . ans ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } 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 ( " Diameter ▁ is ▁ " + diameter ( root ) ) ; } }

Class/struct names: A, GfG, Node
Java program:
import java . io . * ; class GFG { public void getPostOrderBST ( int pre [ ] ) { int pivotPoint = 0 ; for ( int i = 1 ; i < pre . length ; i ++ ) { if ( pre [ 0 ] <= pre [ i ] ) { pivotPoint = i ; break ; } } for ( int i = pivotPoint - 1 ; i > 0 ; i -- ) { System . out . print ( pre [ i ] + " ▁ " ) ; } for ( int i = pre . length - 1 ; i >= pivotPoint ; i -- ) { System . out . print ( pre [ i ] + " ▁ " ) ; } System . out . print ( pre [ 0 ] ) ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void countSubstrings ( String s ) { int ans = 0 ; int subs = 1 ; char pre = '0' ; for ( char i : s . toCharArray ( ) ) { if ( pre == i ) { subs += 1 ; } else { subs = 1 ; } ans += subs ; pre = i ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; countSubstrings ( s ) ; } }

Accumulator variables: ans, subs
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class Pair { int first , second ; Pair ( int first , int second ) { this . first = first ; this . second = second ; } } class GFG { static void find_original_array ( List < Pair > A ) { @ SuppressWarnings ( " unchecked " ) Map < Integer , List < Integer > > mp = new HashMap ( ) ; List < Integer > res = new ArrayList < Integer > ( ) ; @ SuppressWarnings ( " unchecked " ) Map < Integer , Boolean > visited = new HashMap ( ) ; for ( Pair it : A ) { List < Integer > temp ; temp = ( mp . containsKey ( it . first ) ) ? mp . get ( it . first ) : new ArrayList < Integer > ( ) ; temp . add ( it . second ) ; mp . put ( it . first , temp ) ; temp = ( mp . containsKey ( it . second ) ) ? mp . get ( it . second ) : new ArrayList < Integer > ( ) ; temp . add ( it . first ) ; mp . put ( it . second , temp ) ; } int it = 0 ; for ( Map . Entry < Integer , List < Integer > > entry : mp . entrySet ( ) ) { if ( entry . getValue ( ) . size ( ) == 1 ) { it = entry . getKey ( ) ; } } int adjacent = it ; res . add ( it ) ; visited . put ( it , true ) ; while ( res . size ( ) != A . size ( ) + 1 ) { for ( int elements : mp . get ( adjacent ) ) { if ( ! visited . containsKey ( elements ) ) { res . add ( elements ) ; visited . put ( elements , true ) ; adjacent = elements ; } } } for ( int val : res ) { System . out . print ( val + " ▁ " ) ; } } public static void main ( String [ ] args ) { @ SuppressWarnings ( " unchecked " ) List < Pair > A = new ArrayList ( ) ; A . add ( new Pair ( 5 , 1 ) ) ; A . add ( new Pair ( 3 , 4 ) ) ; A . add ( new Pair ( 3 , 5 ) ) ; find_original_array ( A ) ; } }

Iterator variables: elements, it, val
Class/struct names: GFG, Pair
Java program:
class GfG { static void constructTree ( int n , int d , int h ) { if ( d == 1 ) { if ( n == 2 && h == 1 ) { System . out . println ( "1 ▁ 2" ) ; return ; } System . out . println ( " - 1" ) ; return ; } if ( d > 2 * h ) { System . out . println ( " - 1" ) ; return ; } for ( int i = 1 ; i <= h ; i ++ ) System . out . println ( i + " ▁ " + ( i + 1 ) ) ; if ( d > h ) { System . out . println ( "1" + " ▁ " + ( h + 2 ) ) ; for ( int i = h + 2 ; i <= d ; i ++ ) { System . out . println ( i + " ▁ " + ( i + 1 ) ) ; } } for ( int i = d + 1 ; i < n ; i ++ ) { int k = 1 ; if ( d == h ) k = 2 ; System . out . println ( k + " ▁ " + ( i + 1 ) ) ; } } public static void main ( String [ ] args ) { int n = 5 , d = 3 , h = 2 ; constructTree ( n , d , h ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GfG
Java program:
import java . util . * ; public class Main { static int longestsubarray ( int a [ ] , int N ) { int maxlength = 0 , sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( a [ i ] == 1 ) { sum ++ ; } else { sum = 0 ; } maxlength = Math . max ( maxlength , sum ) ; } return maxlength ; } static void solveQueries ( int arr [ ] , int n , Vector < Vector < Integer > > Q , int k ) { int cntQuery = Q . size ( ) ; for ( int i = 0 ; i < cntQuery ; i ++ ) { if ( Q . get ( i ) . get ( 0 ) == 1 ) { System . out . print ( longestsubarray ( arr , n ) + " ▁ " ) ; } else { arr [ Q . get ( i ) . get ( 1 ) - 1 ] ^= 1 ; } } } public static void main ( String [ ] args ) { int N = 10 ; int arr [ ] = { 1 , 1 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 1 } ; Vector < Vector < Integer > > Q = new Vector < Vector < Integer > > ( ) ; Vector < Integer > v1 = new Vector < Integer > ( ) ; Vector < Integer > v2 = new Vector < Integer > ( ) ; Vector < Integer > v3 = new Vector < Integer > ( ) ; v1 . add ( 1 ) ; v2 . add ( 2 ) ; v2 . add ( 3 ) ; v3 . add ( 1 ) ; Q . add ( v1 ) ; Q . add ( v2 ) ; Q . add ( v3 ) ; int K = 3 ; solveQueries ( arr , N , Q , K ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: Main
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void uniqueElements ( int arr [ ] , int start , int K , Map < Integer , Integer > mp ) { Set < Integer > st = new HashSet < > ( ) ; for ( int i = 0 ; i < K ; i ++ ) st . add ( arr [ start + i ] ) ; Iterator itr = st . iterator ( ) ; while ( itr . hasNext ( ) ) { Integer t = ( Integer ) itr . next ( ) ; mp . put ( t , mp . getOrDefault ( t , 0 ) + 1 ) ; } } static void checkAnswer ( Map < Integer , Integer > mp , int N , int K ) { for ( int i = 1 ; i <= N ; i ++ ) { if ( mp . containsKey ( i ) ) if ( mp . get ( i ) == ( N - K + 1 ) ) { System . out . print ( i + " ▁ " ) ; return ; } } System . out . print ( - 1 + " ▁ " ) ; } static void smallestPresentNumber ( int arr [ ] , int N , int K ) { Map < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i <= N - K ; i ++ ) { uniqueElements ( arr , i , K , mp ) ; } checkAnswer ( mp , N , K ) ; } static void generateK ( int arr [ ] , int N ) { for ( int k = 1 ; k <= N ; k ++ ) smallestPresentNumber ( arr , N , k ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 5 , 3 , 2 , 3 , 1 , 3 , 2 , 7 } ; int N = arr . length ; generateK ( arr , N ) ; } }

Accumulator variables: i, k
Iterator variables: i, k
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 getDeepestRightLeafNode ( 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 . poll ( ) ; if ( temp . left != null ) { q . add ( temp . left ) ; } if ( temp . right != null ) { q . add ( temp . right ) ; if ( temp . right . left == null && temp . right . right == null ) result = temp . right ; } } return result ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . right = 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 = getDeepestRightLeafNode ( root ) ; if ( result != null ) System . out . println ( " Deepest ▁ Right ▁ Leaf ▁ Node ▁ : : ▁ " + result . data ) ; else System . out . println ( "No result, right leaf not foundNEW_LINE"); } }

Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static void checkString ( String X , String Y ) { int L = - 1 ; int R = - 1 ; for ( int i = 0 ; i < X . length ( ) ; ++ i ) { if ( X . charAt ( i ) != Y . charAt ( i ) ) { L = i ; break ; } } for ( int i = X . length ( ) - 1 ; i > 0 ; -- i ) { if ( X . charAt ( i ) != Y . charAt ( i ) ) { R = i ; break ; } } X = X . substring ( 0 , L ) + reverse ( X . substring ( L , R + 1 ) ) + X . substring ( R + 1 ) ; if ( X . equals ( Y ) ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } static String reverse ( String input ) { char [ ] a = input . toCharArray ( ) ; int l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . valueOf ( a ) ; } public static void main ( String [ ] args ) { String X = " adcbef " , Y = " abcdef " ; checkString ( X , Y ) ; } }

Index/key variables: l, r
Accumulator variables: l, r
Iterator variables: i, l
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int seg [ ] ; public static int maxLength ( int a [ ] , int b [ ] , int n , int c ) { if ( n == 0 ) return 0 ; int max_length = 0 ; int low = 0 , high = n ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( possible ( a , b , n , c , mid ) ) { max_length = mid ; low = mid + 1 ; } else high = mid - 1 ; } return max_length ; } public static boolean possible ( int a [ ] , int b [ ] , int n , int c , int k ) { int sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { sum += a [ i ] ; } int total_cost = sum * k + getMax ( b , 0 , n - 1 , 0 , k - 1 , 0 ) ; if ( total_cost <= c ) return true ; for ( int i = k ; i < n ; i ++ ) { sum += a [ i ] ; sum -= a [ i - k ] ; total_cost = sum * k + getMax ( b , 0 , n - 1 , i - k + 1 , i , 0 ) ; if ( total_cost <= c ) return true ; } return false ; } public static void build ( int b [ ] , int index , int s , int e ) { if ( s == e ) { seg [ index ] = b [ s ] ; return ; } int mid = s + ( e - s ) / 2 ; build ( b , 2 * index + 1 , s , mid ) ; build ( b , 2 * index + 2 , mid + 1 , e ) ; seg [ index ] = Math . max ( seg [ 2 * index + 1 ] , seg [ 2 * index + 2 ] ) ; } public static int getMax ( int b [ ] , int ss , int se , int qs , int qe , int index ) { if ( se < qs ss > qe ) return Integer . MIN_VALUE / 2 ; if ( ss >= qs && se <= qe ) return seg [ index ] ; int mid = ss + ( se - ss ) / 2 ; return Math . max ( getMax ( b , ss , mid , qs , qe , 2 * index + 1 ) , getMax ( b , mid + 1 , se , qs , qe , 2 * index + 2 ) ) ; } public static void initialiseSegmentTree ( int N ) { seg = new int [ 4 * N ] ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 1 , 6 , 5 , 5 , 6 , 1 } ; int B [ ] = { 14 , 8 , 15 , 15 , 9 , 10 , 7 , 12 } ; int C = 40 ; int N = A . length ; initialiseSegmentTree ( N ) ; build ( B , 0 , 0 , N - 1 ) ; System . out . println ( maxLength ( A , B , N , C ) ) ; } }

Index/key variables: i, index, s
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int maxLength ( int a [ ] , int b [ ] , int n , int c ) { if ( n == 0 ) return 0 ; int max_length = 0 ; int low = 0 , high = n ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( possible ( a , b , n , c , mid ) ) { max_length = mid ; low = mid + 1 ; } else high = mid - 1 ; } return max_length ; } public static boolean possible ( int a [ ] , int b [ ] , int n , int c , int k ) { Deque < Integer > dq = new LinkedList < Integer > ( ) ; int sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { sum += a [ i ] ; while ( dq . size ( ) > 0 && b [ i ] > b [ dq . peekLast ( ) ] ) dq . pollLast ( ) ; dq . addLast ( i ) ; } int total_cost = sum * k + b [ dq . peekFirst ( ) ] ; if ( total_cost <= c ) return true ; for ( int i = k ; i < n ; i ++ ) { sum += a [ i ] ; sum -= a [ i - k ] ; while ( dq . size ( ) > 0 && dq . peekFirst ( ) <= i - k ) dq . pollFirst ( ) ; while ( dq . size ( ) > 0 && b [ i ] > b [ dq . peekLast ( ) ] ) dq . pollLast ( ) ; dq . add ( i ) ; total_cost = sum * k + b [ dq . peekFirst ( ) ] ; if ( total_cost <= c ) return true ; } return false ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 1 , 6 , 5 , 5 , 6 , 1 } ; int B [ ] = { 14 , 8 , 15 , 15 , 9 , 10 , 7 , 12 } ; int N = A . length ; int C = 40 ; System . out . println ( maxLength ( A , B , N , C ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findNthNum ( int N ) { int a = 0 , b , left ; int right , mid ; int t , last_num = 0 ; left = 1 ; right = N ; while ( left <= right ) { mid = left + ( right - left ) / 2 ; t = ( mid * ( mid + 1 ) ) / 2 ; if ( t < N ) { left = mid + 1 ; } else if ( t == N ) { a = mid ; break ; } else { a = mid ; right = mid - 1 ; } } t = a - 1 ; b = N - ( t * ( t + 1 ) ) / 2 - 1 ; System . out . print ( ( 1 << a ) + ( 1 << b ) ) ; } public static void main ( String [ ] args ) { int N = 15 ; findNthNum ( N ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void longestSubWithMaxSum ( int arr [ ] , int N ) { int Max = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; if ( Max < 0 ) { System . out . print ( Max ) ; return ; } for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= 0 ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , - 4 , - 2 , 3 , 0 } ; int N = arr . length ; longestSubWithMaxSum ( arr , N ) ; } }

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