dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { static void LeftRightNode ( int preorder [ ] , int n ) { int min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( min > preorder [ i ] ) min = preorder [ i ] ; if ( max < preorder [ i ] ) max = preorder [ i ] ; } System . out . println ( " Leftmost ▁ node ▁ is ▁ " + min ) ; System . out . println ( " Rightmost ▁ node ▁ is ▁ " + max ) ; } public static void main ( String [ ] args ) { int preorder [ ] = { 3 , 2 , 1 , 5 , 4 } ; int n = 5 ; LeftRightNode ( preorder , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int m = 6 , n = 4 ; static int compareRow ( int a1 [ ] , int a2 [ ] ) { for ( int i = 0 ; i < n ; i ++ ) { if ( a1 [ i ] < a2 [ i ] ) return 1 ; else if ( a1 [ i ] > a2 [ i ] ) return - 1 ; } return 0 ; } static int binaryCheck ( int ar [ ] [ ] , int arr [ ] ) { int l = 0 , r = m - 1 ; while ( l <= r ) { int mid = ( l + r ) / 2 ; int temp = compareRow ( ar [ mid ] , arr ) ; if ( temp == 0 ) return mid + 1 ; else if ( temp == 1 ) l = mid + 1 ; else r = mid - 1 ; } return - 1 ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 0 , 0 , 1 , 0 } , { 10 , 9 , 22 , 23 } , { 40 , 40 , 40 , 40 } , { 43 , 44 , 55 , 68 } , { 81 , 73 , 100 , 132 } , { 100 , 75 , 125 , 133 } } ; int row [ ] = { 10 , 9 , 22 , 23 } ; System . out . println ( binaryCheck ( mat , row ) ) ; } }

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxLen = 30 ; static int findCnt ( int arr [ ] , int n , int k ) { int ans = 0 ; for ( int i = 1 ; i < n ; i ++ ) { arr [ i ] += arr [ i - 1 ] ; if ( arr [ i ] > k arr [ i ] < - 1 * k ) ans ++ ; } if ( arr [ 0 ] > k arr [ 0 ] < - 1 * k ) ans ++ ; Arrays . sort ( arr ) ; for ( int i = 0 ; i < n ; i ++ ) ans += n - upper_bound ( arr , 0 , n , arr [ i ] + k ) ; return ans ; } static int upper_bound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , 4 , - 5 , 6 } ; int n = arr . length ; int k = 0 ; System . out . println ( findCnt ( arr , n , k ) ) ; } }

Index/key variables: i, middle
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int upperBound ( ArrayList < Integer > a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( a . get ( middle ) > element ) { high = middle ; } else { low = middle + 1 ; } } return low ; } static int FindIntersection ( ArrayList < ArrayList < Integer > > type1 , int n , ArrayList < ArrayList < Integer > > type2 , int m ) { int ans = n * m ; ArrayList < Integer > start = new ArrayList < Integer > ( ) ; ArrayList < Integer > end = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { start . add ( type1 . get ( i ) . get ( 0 ) ) ; end . add ( type1 . get ( i ) . get ( 1 ) ) ; } Collections . sort ( start ) ; Collections . sort ( end ) ; for ( int i = 0 ; i < m ; i ++ ) { int L = type2 . get ( i ) . get ( 0 ) ; int R = type2 . get ( i ) . get ( 1 ) ; ans -= start . size ( ) - upperBound ( start , 0 , start . size ( ) , R ) ; ans -= upperBound ( end , 0 , end . size ( ) , L - 1 ) ; } return ans ; } public static void main ( String [ ] args ) { ArrayList < ArrayList < Integer > > type1 = new ArrayList < ArrayList < Integer > > ( ) ; type1 . add ( new ArrayList < Integer > ( Arrays . asList ( 1 , 2 ) ) ) ; type1 . add ( new ArrayList < Integer > ( Arrays . asList ( 2 , 3 ) ) ) ; type1 . add ( new ArrayList < Integer > ( Arrays . asList ( 4 , 5 ) ) ) ; type1 . add ( new ArrayList < Integer > ( Arrays . asList ( 6 , 7 ) ) ) ; ArrayList < ArrayList < Integer > > type2 = new ArrayList < ArrayList < Integer > > ( ) ; type2 . add ( new ArrayList < Integer > ( Arrays . asList ( 1 , 5 ) ) ) ; type2 . add ( new ArrayList < Integer > ( Arrays . asList ( 2 , 3 ) ) ) ; type2 . add ( new ArrayList < Integer > ( Arrays . asList ( 4 , 7 ) ) ) ; type2 . add ( new ArrayList < Integer > ( Arrays . asList ( 5 , 7 ) ) ) ; int n = type1 . size ( ) ; int m = type2 . size ( ) ; System . out . println ( FindIntersection ( type1 , n , type2 , m ) ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int lcm ( int a , int b ) { return ( a * b ) / gcd ( a , b ) ; } static int divTermCount ( int a , int b , int c , int num ) { return ( ( num / a ) + ( num / b ) + ( num / c ) - ( num / lcm ( a , b ) ) - ( num / lcm ( b , c ) ) - ( num / lcm ( a , c ) ) + ( num / lcm ( a , lcm ( b , c ) ) ) ) ; } static int findNthTerm ( int a , int b , int c , int n ) { int low = 1 , high = Integer . MAX_VALUE , mid ; while ( low < high ) { mid = low + ( high - low ) / 2 ; if ( divTermCount ( a , b , c , mid ) < n ) low = mid + 1 ; else high = mid ; } return low ; } public static void main ( String [ ] args ) { int a = 2 , b = 3 , c = 5 , n = 10 ; System . out . println ( findNthTerm ( a , b , c , n ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static boolean check ( int mid , int array [ ] , int n , int K ) { int count = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( array [ i ] > mid ) return false ; sum += array [ i ] ; if ( sum > mid ) { count ++ ; sum = array [ i ] ; } } count ++ ; if ( count <= K ) return true ; return false ; } static int solve ( int array [ ] , int n , int K ) { int start = 1 ; for ( int i = 0 ; i < n ; ++ i ) { if ( array [ i ] > start ) } int end = 0 ; for ( int i = 0 ; i < n ; i ++ ) { } int answer = 0 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( check ( mid , array , n , K ) ) { answer = mid ; end = mid - 1 ; } else { start = mid + 1 ; } } return answer ; } public static void main ( String [ ] args ) { int array [ ] = { 1 , 2 , 3 , 4 } ; int n = array . length ; int K = 3 ; System . out . println ( solve ( array , n , K ) ) ; } }

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void createSorted ( int a [ ] , int n ) { Vector < Integer > b = new Vector < > ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( b . isEmpty ( ) ) b . add ( a [ j ] ) ; else { int start = 0 , end = b . size ( ) - 1 ; int pos = 0 ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; if ( b . get ( mid ) == a [ j ] ) { b . add ( ( Math . max ( 0 , mid + 1 ) ) , a [ j ] ) ; break ; } else if ( b . get ( mid ) > a [ j ] ) pos = end = mid - 1 ; else pos = start = mid + 1 ; if ( start > end ) { pos = start ; b . add ( Math . max ( 0 , pos ) , a [ j ] ) ; break ; } } } } for ( int i = 0 ; i < n ; i ++ ) System . out . print ( b . get ( i ) + " ▁ " ) ; } public static void main ( String args [ ] ) { int a [ ] = { 2 , 5 , 4 , 9 , 8 } ; int n = a . length ; createSorted ( a , n ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static final int MAX = 26 ; static boolean atLeastK ( int freq [ ] , int k ) { for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] != 0 && freq [ i ] < k ) return false ; } return true ; } static void setZero ( int freq [ ] ) { for ( int i = 0 ; i < MAX ; i ++ ) freq [ i ] = 0 ; } static int findlength ( String str , int n , int k ) { int maxLen = 0 ; int freq [ ] = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { setZero ( freq ) ; for ( int j = i ; j < n ; j ++ ) { freq [ str . charAt ( j ) - ' a ' ] ++ ; if ( atLeastK ( freq , k ) ) { maxLen = Math . max ( maxLen , j - i + 1 ) ; } } } return maxLen ; } public static void main ( String args [ ] ) { String str = " xyxyyz " ; int n = str . length ( ) ; int k = 2 ; System . out . println ( findlength ( str , n , k ) ) ; } }

Index/key variables: MAX, i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static boolean check ( int m , int n , int arr [ ] ) { int [ ] desired = new int [ n ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { desired [ i ] = m ; m -- ; } for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > desired [ i ] desired [ i ] < 1 ) { return false ; } } return true ; } static int minOperations ( int arr [ ] , int n ) { int start = ( int ) arr [ n - 1 ] ; int end = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) + n ; int max_arr = 0 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( check ( mid , n , arr ) ) { max_arr = mid ; end = mid - 1 ; } else { start = mid + 1 ; } } int [ ] desired = new int [ n ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { desired [ i ] = max_arr ; max_arr -- ; } int operations = 0 ; for ( int i = 0 ; i < n ; i ++ ) { operations += ( desired [ i ] - arr [ i ] ) ; } return operations ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 4 , 5 , 5 , 7 } ; int n = arr . length ; System . out . println ( minOperations ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i, m, max_arr, operations
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . HashSet ; class GFG { static class Node { int data ; Node next ; } ; static Node head ; static void insert ( Node ref_head , int item ) { Node temp = new Node ( ) ; temp . data = item ; temp . next = ref_head ; head = temp ; } static int countNode ( Node head ) { if ( head == null ) return 0 ; ; HashSet < Integer > s = new HashSet < > ( ) ; s . add ( head . data ) ; int count = 0 ; for ( Node curr = head . next ; curr != null ; curr = curr . next ) { if ( s . contains ( curr . data ) ) count ++ ; s . add ( curr . data ) ; } return count ; } public static void main ( String [ ] args ) { insert ( head , 5 ) ; insert ( head , 7 ) ; insert ( head , 5 ) ; insert ( head , 1 ) ; insert ( head , 7 ) ; System . out . println ( countNode ( head ) ) ; } }

Accumulator variables: count
Iterator variables: curr
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static int minSteps ( int arr [ ] , int n ) { boolean [ ] v = new boolean [ n ] ; Queue < Integer > q = new LinkedList < > ( ) ; q . add ( 0 ) ; int depth = 0 ; while ( q . size ( ) > 0 ) { int x = q . size ( ) ; while ( x -- > 0 ) { int i = q . peek ( ) ; q . poll ( ) ; if ( v [ i ] ) continue ; if ( i == n - 1 ) return depth ; v [ i ] = true ; if ( i + arr [ i ] < n ) q . add ( i + arr [ i ] ) ; if ( i - arr [ i ] >= 0 ) q . add ( i - arr [ i ] ) ; } depth ++ ; } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 1 , 1 , 1 , 1 } ; int n = arr . length ; System . out . println ( minSteps ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: depth, x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int divisorcount ( int elem ) { int ans = 0 ; for ( int i = 1 ; i <= Math . sqrt ( elem ) ; i ++ ) { if ( elem % i == 0 ) { if ( i * i == elem ) ans ++ ; else ans += 2 ; } } return ans ; } static String findwinner ( int A [ ] , int B [ ] , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = divisorcount ( A [ i ] ) ; } for ( int i = 0 ; i < M ; i ++ ) { B [ i ] = divisorcount ( B [ i ] ) ; } Arrays . sort ( A ) ; Arrays . sort ( B ) ; int winA = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int val = A [ i ] ; int start = 0 ; int end = M - 1 ; int index = - 1 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( B [ mid ] <= val ) { index = mid ; start = mid + 1 ; } else { end = mid - 1 ; } } winA += ( index + 1 ) ; } int winB = N * M - winA ; if ( winA > winB ) { return " A " ; } else if ( winB > winA ) { return " B " ; } return " Draw " ; } public static void main ( String [ ] args ) { int A [ ] = { 4 , 12 , 24 } ; int N = A . length ; int B [ ] = { 25 , 28 , 13 , 45 } ; int M = B . length ; System . out . print ( findwinner ( A , B , N , M ) ) ; } }

Index/key variables: i, mid
Accumulator variables: ans, i, winA
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static boolean isPossible ( int box [ ] , int truck [ ] , int n , int m , int min_time ) { int temp = 0 ; int count = 0 ; while ( count < m ) { for ( int j = 0 ; j < min_time && temp < n && truck [ count ] >= box [ temp ] ; j += 2 ) temp ++ ; count ++ ; } if ( temp == n ) return true ; return false ; } static int minTime ( int box [ ] , int truck [ ] , int n , int m ) { Arrays . sort ( box ) ; Arrays . sort ( truck ) ; int l = 0 ; int h = 2 * n ; int min_time = 0 ; while ( l <= h ) { int mid = ( l + h ) / 2 ; if ( isPossible ( box , truck , n , m , mid ) ) { min_time = mid ; h = mid - 1 ; } else l = mid + 1 ; } return min_time ; } public static void main ( String [ ] args ) { int box [ ] = { 10 , 2 , 16 , 19 } ; int truck [ ] = { 29 , 25 } ; int n = box . length ; int m = truck . length ; System . out . printf ( " % d " , minTime ( box , truck , n , m ) ) ; } }

Index/key variables: count, temp
Accumulator variables: count, j, temp
Iterator variables: j
Class/struct names: GFG
Java program:
class GFG { static void solve ( int interval [ ] [ ] , int N , int Q ) { int Mark [ ] = new int [ Q ] ; for ( int i = 0 ; i < N ; i ++ ) { int l = interval [ i ] [ 0 ] - 1 ; int r = interval [ i ] [ 1 ] - 1 ; for ( int j = l ; j <= r ; j ++ ) Mark [ j ] ++ ; } int count = 0 ; for ( int i = 0 ; i < Q ; i ++ ) { if ( Mark [ i ] != 0 ) count ++ ; } int count1 [ ] = new int [ Q ] ; if ( Mark [ 0 ] == 1 ) count1 [ 0 ] = 1 ; for ( int i = 1 ; i < Q ; i ++ ) { if ( Mark [ i ] == 1 ) count1 [ i ] = count1 [ i - 1 ] + 1 ; else count1 [ i ] = count1 [ i - 1 ] ; } int maxindex = 0 ; int maxcoverage = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int l = interval [ i ] [ 0 ] - 1 ; int r = interval [ i ] [ 1 ] - 1 ; int elem1 ; if ( l != 0 ) elem1 = count1 [ r ] - count1 [ l - 1 ] ; else elem1 = count1 [ r ] ; if ( count - elem1 >= maxcoverage ) { maxcoverage = count - elem1 ; maxindex = i ; } } System . out . println ( " Maximum ▁ Coverage ▁ is ▁ " + maxcoverage + " ▁ after ▁ removing ▁ interval ▁ at ▁ index ▁ " + maxindex ) ; } public static void main ( String [ ] args ) { int interval [ ] [ ] = { { 1 , 4 } , { 4 , 5 } , { 5 , 6 } , { 6 , 7 } , { 3 , 5 } } ; int N = interval . length ; int Q = 7 ; solve ( interval , N , Q ) ; } }

Index/key variables: Q, i, j, r
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static boolean isPossible ( int arr [ ] , int n , int dist , int k ) { int req = 0 ; int curr = 0 ; int prev = 0 ; for ( int i = 0 ; i < n ; i ++ ) { while ( curr != n && arr [ curr ] - arr [ prev ] <= dist ) { curr ++ ; } req ++ ; if ( curr == n ) { break ; } prev = curr - 1 ; } if ( curr != n ) { return false ; } if ( req <= k ) { return true ; } return false ; } static int minDistance ( int arr [ ] , int n , int k ) { int l = 0 ; int h = arr [ n - 1 ] ; int ans = 0 ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( isPossible ( arr , n , m , k ) ) { ans = m ; h = m - 1 ; } else { l = m + 1 ; } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 15 , 36 , 43 } ; int n = arr . length ; int k = 2 ; System . out . println ( minDistance ( arr , n , k ) ) ; } }

Index/key variables: curr, prev
Accumulator variables: curr, i, req
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int getKthElement ( int n , int k , int L [ ] , int R [ ] ) { int l = 1 ; int h = n ; int total [ ] = new int [ n + 1 ] ; total [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { total [ i + 1 ] = total [ i ] + ( R [ i ] - L [ i ] ) + 1 ; } int index = - 1 ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( total [ m ] > k ) { index = m ; h = m - 1 ; } else if ( total [ m ] < k ) l = m + 1 ; else { index = m ; break ; } } l = L [ index - 1 ] ; h = R [ index - 1 ] ; int x = k - total [ index - 1 ] ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( ( m - L [ index - 1 ] ) + 1 == x ) { return m ; } else if ( ( m - L [ index - 1 ] ) + 1 > x ) h = m - 1 ; else l = m + 1 ; } return k ; } public static void main ( String [ ] args ) { int L [ ] = { 1 , 8 , 21 } ; int R [ ] = { 4 , 10 , 23 } ; int n = L . length ; int k = 6 ; System . out . println ( getKthElement ( n , k , L , R ) ) ; } }

Index/key variables: i, m
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int MinimumX ( int a , int b , int c , int k ) { int x = Integer . MAX_VALUE ; if ( k <= c ) return 0 ; int h = k - c ; int l = 0 ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( ( a * m * m ) + ( b * m ) > ( k - c ) ) { x = Math . min ( x , m ) ; h = m - 1 ; } else if ( ( a * m * m ) + ( b * m ) < ( k - c ) ) l = m + 1 ; else return m ; } return x ; } public static void main ( String [ ] args ) { int a = 3 , b = 2 , c = 4 , k = 15 ; System . out . println ( MinimumX ( a , b , c , k ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void IfExists ( int arr [ ] , int n ) { int sum [ ] = new int [ n ] ; Arrays . sort ( arr ) ; sum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i ] ; int max = arr [ n - 1 ] ; boolean flag = false ; for ( int i = 1 ; i <= max ; i ++ ) { int findex = 0 ; int lindex = 0 ; int l = 0 ; int r = n - 1 ; while ( l <= r ) { int m = ( l + r ) / 2 ; if ( arr [ m ] < i ) { findex = m ; l = m + 1 ; } else r = m - 1 ; } l = 1 ; r = n ; flag = false ; while ( l <= r ) { int m = ( r + l ) / 2 ; if ( arr [ m ] > i ) { lindex = m ; r = m - 1 ; } else l = m + 1 ; } if ( sum [ findex ] == sum [ n - 1 ] - sum [ lindex - 1 ] ) { flag = true ; break ; } } if ( flag ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 2 , 5 } ; int n = arr . length ; IfExists ( arr , n ) ; } }

Index/key variables: findex, i, m, n
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
class GFG { public static int findMissing ( int arr [ ] , int n ) { int l = 0 , h = n - 1 ; int mid ; while ( h > l ) { mid = l + ( h - l ) / 2 ; if ( arr [ mid ] - mid == arr [ 0 ] ) { if ( arr [ mid + 1 ] - arr [ mid ] > 1 ) return arr [ mid ] + 1 ; else { l = mid + 1 ; } } else { if ( arr [ mid ] - arr [ mid - 1 ] > 1 ) return arr [ mid ] - 1 ; else { h = mid - 1 ; } } } return - 1 ; } public static void main ( String args [ ] ) { int arr [ ] = { - 9 , - 8 , - 7 , - 5 , - 4 , - 3 , - 2 , - 1 , 0 } ; int n = arr . length ; System . out . print ( findMissing ( arr , n ) ) ; } }

Index/key variables: mid
Class/struct names: GFG
Java program:
class GFG { static int maxSum ( int arr [ ] , int n , int K ) { int maximum = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int sumk = 0 ; for ( int j = i ; j < n ; j += K ) sumk = sumk + arr [ j ] ; maximum = Math . max ( maximum , sumk ) ; } return maximum ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 6 , 4 , 7 , 2 } ; int n = arr . length ; int K = 2 ; System . out . println ( maxSum ( arr , n , K ) ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int countGreater ( int arr [ ] , int n , int k ) { int l = 0 ; int r = n - 1 ; int leftGreater = n ; while ( l <= r ) { int m = l + ( r - l ) / 2 ; if ( arr [ m ] > k ) { leftGreater = m ; r = m - 1 ; } else l = m + 1 ; } return ( n - leftGreater ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 3 , 4 , 7 , 7 , 7 , 11 , 13 , 13 } ; int n = arr . length ; int k = 7 ; System . out . println ( countGreater ( arr , n , k ) ) ; } }

Index/key variables: m
Class/struct names: GFG
Java program:
class GFG { static int operations ( int op [ ] , int n , int k ) { int i , count = 0 ; int nVal = 0 ; int min = Integer . MAX_VALUE ; for ( i = 0 ; i < n ; i ++ ) { nVal += op [ i ] ; min = Math . min ( min , nVal ) ; if ( ( k + nVal ) <= 0 ) return ( i + 1 ) ; } if ( nVal >= 0 ) return - 1 ; int times = ( k - Math . abs ( min ) ) / Math . abs ( nVal ) ; k = ( k - ( times * Math . abs ( nVal ) ) ) ; count = ( times * n ) ; while ( k > 0 ) { for ( i = 0 ; i < n ; i ++ ) { k = k + op [ i ] ; count ++ ; if ( k <= 0 ) break ; } } return count ; } public static void main ( String [ ] args ) { int op [ ] = { - 60 , 65 , - 1 , 14 , - 25 } ; int n = op . length ; int k = 100000 ; System . out . print ( operations ( op , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: count, i, nVal
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int MAX_SIZE = 1000 ; static int lookup_table [ ] = new int [ MAX_SIZE ] ; static void create_table ( int n ) { int pow = 1 ; int co = 0 ; do { pow <<= 1 ; lookup_table [ co ] = ( n + ( pow >> 1 ) ) / pow ; } while ( lookup_table [ co ++ ] != 0 ) ; } static int binary ( int arr [ ] , int v ) { int index = lookup_table [ 0 ] - 1 ; int co = 0 ; while ( lookup_table [ co ] != 0 ) { if ( v == arr [ index ] ) return index ; else if ( v < arr [ index ] ) { index -= lookup_table [ ++ co ] ; return index ; } else { index += lookup_table [ ++ co ] ; return index ; } } return index ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 6 , 7 , 8 , 9 } ; int n = arr . length ; create_table ( n ) ; System . out . println ( " Position ▁ of ▁ 3 ▁ in ▁ array ▁ = ▁ " + binary ( arr , 3 ) ) ; } }

Index/key variables: MAX_SIZE, co, index
Accumulator variables: co, index
Class/struct names: GFG
Java program:
class GFG { static int countFactor ( int P , int X ) { if ( X < P ) return 0 ; return ( X / P + countFactor ( P , X / P ) ) ; } static int findSmallestX ( int Y ) { int low = 0 , high = 5 * Y ; int N = 0 ; while ( low <= high ) { int mid = ( high + low ) / 2 ; if ( countFactor ( 5 , mid ) < Y ) { low = mid + 1 ; } else { N = mid ; high = mid - 1 ; } } return N ; } public static void main ( String args [ ] ) { int Y = 10 ; System . out . println ( findSmallestX ( Y ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static long squareSum ( long N ) { long sum = ( long ) ( N * ( N + 1 ) * ( 2 * N + 1 ) ) / 6 ; return sum ; } static long findMaxN ( long X ) { long low = 1 , high = 100000 ; int N = 0 ; while ( low <= high ) { long mid = ( high + low ) / 2 ; if ( squareSum ( mid ) <= X ) { N = ( int ) mid ; low = mid + 1 ; } else high = mid - 1 ; } return N ; } public static void main ( String [ ] args ) { long X = 25 ; System . out . println ( findMaxN ( X ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int findNumber ( pair a [ ] , int n , int K ) { for ( int i = 0 ; i < n ; i ++ ) { if ( K >= a [ i ] . first && K <= a [ i ] . second ) return i ; } return - 1 ; } public static void main ( String [ ] args ) { pair a [ ] = { new pair ( 1 , 3 ) , new pair ( 4 , 7 ) , new pair ( 8 , 11 ) } ; int n = a . length ; int k = 6 ; int index = findNumber ( a , n , k ) ; if ( index != - 1 ) System . out . println ( index ) ; else System . out . println ( - 1 ) ; } }

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