dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; import java . io . * ; class GFG { static int maxSubarraySum ( int arr [ ] , int N , int K ) { Set < Integer > cum_set = new HashSet < > ( ) ; cum_set . add ( 0 ) ; int max_sum = Integer . MIN_VALUE , cSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { cSum += arr [ i ] ; ArrayList < Integer > al = new ArrayList < > ( ) ; Iterator < Integer > it = cum_set . iterator ( ) ; int end = 0 ; while ( it . hasNext ( ) ) { end = it . next ( ) ; al . add ( end ) ; } Collections . sort ( al ) ; int sit = lower_bound ( al , cSum - K ) ; if ( sit != end ) max_sum = Math . max ( max_sum , cSum - sit ) ; cum_set . add ( cSum ) ; } return max_sum ; } static int lower_bound ( ArrayList < Integer > al , int x ) { int l = - 1 , r = al . size ( ) ; while ( l + 1 < r ) { int m = ( l + r ) >>> 1 ; if ( al . get ( m ) >= x ) r = m ; else l = m ; } return r ; } public static void main ( String args [ ] ) { int arr [ ] = { 5 , - 2 , 6 , 3 , - 5 } ; int K = 15 ; int N = arr . length ; System . out . println ( maxSubarraySum ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: cSum, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void printAllAPTriplets ( int [ ] arr , int n ) { ArrayList < Integer > s = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int diff = arr [ j ] - arr [ i ] ; boolean exists = s . contains ( arr [ i ] - diff ) ; if ( exists ) System . out . println ( arr [ i ] - diff + " ▁ " + arr [ i ] + " ▁ " + arr [ j ] ) ; } s . add ( arr [ i ] ) ; } } public static void main ( String args [ ] ) { int [ ] arr = { 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 } ; int n = arr . length ; printAllAPTriplets ( arr , n ) ; } }

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 void findAllTriplets ( int arr [ ] , int n ) { for ( int i = 1 ; i < n - 1 ; i ++ ) { for ( int j = i - 1 , k = i + 1 ; j >= 0 && k < n ; ) { if ( arr [ j ] + arr [ k ] == 2 * arr [ i ] ) { System . out . println ( arr [ j ] + " ▁ " + arr [ i ] + " ▁ " + arr [ k ] ) ; k ++ ; j -- ; } else if ( arr [ j ] + arr [ k ] < 2 * arr [ i ] ) k ++ ; else j -- ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 } ; int n = arr . length ; findAllTriplets ( arr , n ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class Node { int data ; Node left ; Node right ; Node ( int data ) { this . data = data ; this . left = null ; this . right = null ; } } class GFG { static boolean existPathUtil ( Node root , int arr [ ] , int n , int index ) { if ( root == null index == n ) return false ; if ( root . left == null && root . right == null ) { if ( ( root . data == arr [ index ] ) && ( index == n - 1 ) ) return true ; return false ; } return ( ( index < n ) && ( root . data == arr [ index ] ) && ( existPathUtil ( root . left , arr , n , index + 1 ) || existPathUtil ( root . right , arr , n , index + 1 ) ) ) ; } static boolean existPath ( Node root , int arr [ ] , int n , int index ) { if ( root == null ) return ( n == 0 ) ; return existPathUtil ( root , arr , n , 0 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 8 , 6 , 7 } ; int n = arr . length ; Node root = new Node ( 5 ) ; root . left = new Node ( 3 ) ; root . right = new Node ( 8 ) ; root . left . left = new Node ( 2 ) ; root . left . right = new Node ( 4 ) ; root . left . left . left = new Node ( 1 ) ; root . right . left = new Node ( 6 ) ; root . right . left . right = new Node ( 7 ) ; if ( existPath ( root , arr , n , 0 ) ) System . out . println ( " Path ▁ Exists " ) ; else System . out . println ( " Path ▁ does ▁ not ▁ Exist " ) ; } }

Index/key variables: index
Class/struct names: GFG, Node
Java program:
import java . util . * ; public class Main { public static void findTriplets ( int a [ ] , int n , int sum ) { int i ; Arrays . sort ( a ) ; boolean flag = false ; for ( i = 0 ; i < n - 2 ; i ++ ) { if ( i == 0 a [ i ] > a [ i - 1 ] ) { int start = i + 1 ; int end = n - 1 ; int target = sum - a [ i ] ; while ( start < end ) { if ( start > i + 1 && a [ start ] == a [ start - 1 ] ) { start ++ ; continue ; } if ( end < n - 1 && a [ end ] == a [ end + 1 ] ) { end -- ; continue ; } if ( target == a [ start ] + a [ end ] ) { System . out . print ( " [ " + a [ i ] + " , " + a [ start ] + " , " + a [ end ] + " ] ▁ " ) ; flag = true ; start ++ ; end -- ; } else if ( target > ( a [ start ] + a [ end ] ) ) { start ++ ; } else { end -- ; } } } } if ( flag == false ) { System . out . print ( " No ▁ Such ▁ Triplets ▁ Exist " ) ; } } public static void main ( String [ ] args ) { int a [ ] = { 12 , 3 , 6 , 1 , 6 , 9 } ; int n = a . length ; int sum = 24 ; findTriplets ( a , n , sum ) ; } }

Index/key variables: end, i, start
Accumulator variables: end, i, start
Iterator variables: i
Boolean variables: flag
Class/struct names: Main
Java program:
import java . io . * ; class GFG { static int m = 6 , n = 4 ; static int linearCheck ( int ar [ ] [ ] , int arr [ ] ) { for ( int i = 0 ; i < m ; i ++ ) { boolean matched = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( ar [ i ] [ j ] != arr [ j ] ) { matched = false ; break ; } } if ( matched ) return i + 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 ( linearCheck ( mat , row ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: matched
Class/struct names: GFG
Java program:
class GFG { static int countTriplets ( int arr [ ] , int n , int m ) { int count = 0 ; for ( int i = 0 ; i < n - 2 ; i ++ ) for ( int j = i + 1 ; j < n - 1 ; j ++ ) for ( int k = j + 1 ; k < n ; k ++ ) if ( arr [ i ] * arr [ j ] * arr [ k ] == m ) count ++ ; return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 6 , 2 , 3 , 8 } ; int m = 24 ; System . out . println ( countTriplets ( arr , arr . length , m ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . HashMap ; class GFG { static int countTriplets ( int arr [ ] , int n , int m ) { HashMap < Integer , Integer > occ = new HashMap < Integer , Integer > ( n ) ; for ( int i = 0 ; i < n ; i ++ ) occ . put ( arr [ i ] , i ) ; int count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( ( arr [ i ] * arr [ j ] <= m ) && ( arr [ i ] * arr [ j ] != 0 ) && ( m % ( arr [ i ] * arr [ j ] ) == 0 ) ) { int check = m / ( arr [ i ] * arr [ j ] ) ; occ . containsKey ( check ) ; if ( check != arr [ i ] && check != arr [ j ] && occ . containsKey ( check ) && occ . get ( check ) > i && occ . get ( check ) > j ) count ++ ; } } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 6 , 2 , 3 , 8 } ; int m = 24 ; System . out . println ( countTriplets ( arr , arr . length , m ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int countPairs ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] == arr [ j ] ) ans ++ ; return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 2 } ; int n = arr . length ; System . out . println ( countPairs ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static class pair { int first , second ; pair ( int a , int b ) { first = a ; second = b ; } } static void preCalculate ( int binary [ ] , int n , pair left [ ] ) { int count1 = 0 , count0 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { left [ i ] . first = count1 ; left [ i ] . second = count0 ; if ( binary [ i ] != 0 ) count1 ++ ; else count0 ++ ; } } public static void main ( String args [ ] ) { int binary [ ] = { 1 , 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 } ; int n = binary . length ; pair left [ ] = new pair [ n ] ; for ( int i = 0 ; i < n ; i ++ ) left [ i ] = new pair ( 0 , 0 ) ; preCalculate ( binary , n , left ) ; int queries [ ] = { 0 , 1 , 2 , 4 } ; int q = queries . length ; for ( int i = 0 ; i < q ; i ++ ) System . out . println ( left [ queries [ i ] ] . first + " ▁ ones ▁ " + left [ queries [ i ] ] . second + " zerosNEW_LINE"); } }

Index/key variables: i, n
Accumulator variables: count0, count1, i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { public static int countPairs ( int arr [ ] , int n ) { HashMap < Integer , Integer > hm = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( hm . containsKey ( arr [ i ] ) ) hm . put ( arr [ i ] , hm . get ( arr [ i ] ) + 1 ) ; else hm . put ( arr [ i ] , 1 ) ; } int ans = 0 ; for ( Map . Entry < Integer , Integer > it : hm . entrySet ( ) ) { int count = it . getValue ( ) ; ans += ( count * ( count - 1 ) ) / 2 ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 1 , 2 , 3 , 1 } ; System . out . println ( countPairs ( arr , arr . length ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
public class Main { public static int pos1 = - 1 ; public static int pos2 = - 1 ; public static boolean equiSumUtil ( int [ ] arr ) { int n = arr . length ; int [ ] pre = new int [ n ] ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; pre [ i ] = sum ; } int [ ] suf = new int [ n ] ; sum = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { sum += arr [ i ] ; suf [ i ] = sum ; } int total_sum = sum ; int i = 0 , j = n - 1 ; while ( i < j - 1 ) { if ( pre [ i ] == total_sum / 3 ) { pos1 = i ; } if ( suf [ j ] == total_sum / 3 ) { pos2 = j ; } if ( pos1 != - 1 && pos2 != - 1 ) { if ( suf [ pos1 + 1 ] - suf [ pos2 ] == total_sum / 3 ) { return true ; } else { return false ; } } if ( pre [ i ] < suf [ j ] ) { i ++ ; } else { j -- ; } } return false ; } public static void equiSum ( int [ ] arr ) { boolean ans = equiSumUtil ( arr ) ; if ( ans ) { System . out . print ( " First ▁ Segment ▁ : ▁ " ) ; for ( int i = 0 ; i <= pos1 ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } System . out . println ( ) ; System . out . print ( " Second ▁ Segment ▁ : ▁ " ) ; for ( int i = pos1 + 1 ; i < pos2 ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } System . out . println ( ) ; System . out . print ( " Third ▁ Segment ▁ : ▁ " ) ; for ( int i = pos2 ; i < arr . length ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } System . out . println ( ) ; } else { System . out . println ( " Array ▁ cannot ▁ be ▁ " + " divided ▁ into ▁ three ▁ equal ▁ sum ▁ segments " ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 6 , 2 , 7 , 1 , 2 , 8 } ; equiSum ( arr ) ; } }

Index/key variables: i, j, n, pos2
Accumulator variables: i, j, sum
Iterator variables: i
Class/struct names: Main
Java program:
public class GFG { static int p = 101 ; static int MOD = 1000000007 ; static class Query { int L , R ; public Query ( int L , int R ) { this . L = L ; this . R = R ; } } ; static boolean isPalindrome ( String str , int L , int R ) { while ( R > L ) { if ( str . charAt ( L ++ ) != str . charAt ( R -- ) ) { return ( false ) ; } } return ( true ) ; } static int modPow ( int base , int exponent ) { if ( exponent == 0 ) { return 1 ; } if ( exponent == 1 ) { return base ; } int temp = modPow ( base , exponent / 2 ) ; if ( exponent % 2 == 0 ) { return ( temp % MOD * temp % MOD ) % MOD ; } else { return ( ( ( temp % MOD * temp % MOD ) % MOD ) * base % MOD ) % MOD ; } } static int findMMI ( int n ) { return modPow ( n , MOD - 2 ) ; } static void computePrefixHash ( String str , int n , int prefix [ ] , int power [ ] ) { prefix [ 0 ] = 0 ; prefix [ 1 ] = str . charAt ( 0 ) ; for ( int i = 2 ; i <= n ; i ++ ) { prefix [ i ] = ( prefix [ i - 1 ] % MOD + ( str . charAt ( i - 1 ) % MOD * power [ i - 1 ] % MOD ) % MOD ) % MOD ; } return ; } static void computeSuffixHash ( String str , int n , int suffix [ ] , int power [ ] ) { suffix [ 0 ] = 0 ; suffix [ 1 ] = str . charAt ( n - 1 ) ; for ( int i = n - 2 , j = 2 ; i >= 0 && j <= n ; i -- , j ++ ) { suffix [ j ] = ( suffix [ j - 1 ] % MOD + ( str . charAt ( i ) % MOD * power [ j - 1 ] % MOD ) % MOD ) % MOD ; } return ; } static void queryResults ( String str , Query q [ ] , int m , int n , int prefix [ ] , int suffix [ ] , int power [ ] ) { for ( int i = 0 ; i <= m - 1 ; i ++ ) { int L = q [ i ] . L ; int R = q [ i ] . R ; long hash_LR = ( ( prefix [ R + 1 ] - prefix [ L ] + MOD ) % MOD * findMMI ( power [ L ] ) % MOD ) % MOD ; long reverse_hash_LR = ( ( suffix [ n - L ] - suffix [ n - R - 1 ] + MOD ) % MOD * findMMI ( power [ n - R - 1 ] ) % MOD ) % MOD ; if ( hash_LR == reverse_hash_LR ) { if ( isPalindrome ( str , L , R ) == true ) { System . out . printf ( " The ▁ Substring ▁ [ % d ▁ % d ] ▁ is ▁ a ▁ " + "palindromeNEW_LINE", L, R); } else { System . out . printf ( " The ▁ Substring ▁ [ % d ▁ % d ] ▁ is ▁ not ▁ a ▁ " + "palindromeNEW_LINE", L, R); } } else { System . out . printf ( " The ▁ Substring ▁ [ % d ▁ % d ] ▁ is ▁ not ▁ a ▁ " + "palindromeNEW_LINE", L, R); } } return ; } static void computePowers ( int power [ ] , int n ) { power [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { power [ i ] = ( power [ i - 1 ] % MOD * p % MOD ) % MOD ; } return ; } public static void main ( String [ ] args ) { String str = " abaaabaaaba " ; int n = str . length ( ) ; int [ ] power = new int [ n + 1 ] ; computePowers ( power , n ) ; int [ ] prefix = new int [ n + 1 ] ; int [ ] suffix = new int [ n + 1 ] ; computePrefixHash ( str , n , prefix , power ) ; computeSuffixHash ( str , n , suffix , power ) ; Query q [ ] = { new Query ( 0 , 10 ) , new Query ( 5 , 8 ) , new Query ( 2 , 5 ) , new Query ( 5 , 9 ) } ; int m = q . length ; queryResults ( str , q , m , n , prefix , suffix , power ) ; } }

Index/key variables: L, i, j
Accumulator variables: L, R, i, j
Iterator variables: i
Class/struct names: GFG, Query
Java program:
class GfG { static class Node { int data ; Node left , right ; } static Node newNode ( int item ) { Node temp = new Node ( ) ; temp . data = item ; temp . left = null ; temp . right = null ; return temp ; } static int getLevel ( Node root , Node node , int level ) { if ( root == null ) return 0 ; if ( root == node ) return level ; int downlevel = getLevel ( root . left , node , level + 1 ) ; if ( downlevel != 0 ) return downlevel ; return getLevel ( root . right , node , level + 1 ) ; } static void printGivenLevel ( Node root , Node node , int level ) { if ( root == null level < 2 ) return ; if ( level == 2 ) { if ( root . left == node root . right == node ) return ; if ( root . left != null ) System . out . print ( root . left . data + " ▁ " ) ; if ( root . right != null ) System . out . print ( root . right . data + " ▁ " ) ; } else if ( level > 2 ) { printGivenLevel ( root . left , node , level - 1 ) ; printGivenLevel ( root . right , node , level - 1 ) ; } } static void printCousins ( Node root , Node node ) { int level = getLevel ( root , node , 1 ) ; printGivenLevel ( root , node , level ) ; } 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 . right = newNode ( 15 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . right . left . right = newNode ( 8 ) ; printCousins ( root , root . left . right ) ; } }

Class/struct names: GfG, Node
Java program:
public class GFG { public static int getRightMin ( int arr [ ] , int n ) { int min = arr [ 0 ] ; int rightMin = 0 ; int i = 1 ; while ( i < n ) { if ( arr [ i ] == min ) rightMin = i ; i *= 2 ; } i = rightMin + 1 ; while ( i < n && arr [ i ] == min ) { rightMin = i ; i ++ ; } return rightMin ; } public static int getLeftMax ( int arr [ ] , int n ) { int max = arr [ n - 1 ] ; int leftMax = n - 1 ; int i = n - 2 ; while ( i > 0 ) { if ( arr [ i ] == max ) leftMax = i ; i /= 2 ; } i = leftMax - 1 ; while ( i >= 0 && arr [ i ] == max ) { leftMax = i ; i -- ; } return leftMax ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 0 , 1 , 2 , 5 , 5 , 6 , 8 , 8 } ; int n = arr . length ; System . out . println ( " Minimum ▁ left ▁ : ▁ " + 0 ) ; System . out . println ( " Minimum ▁ right ▁ : ▁ " + getRightMin ( arr , n ) ) ; System . out . println ( " Maximum ▁ left ▁ : ▁ " + getLeftMax ( arr , n ) ) ; System . out . println ( " Maximum ▁ right ▁ : ▁ " + ( n - 1 ) ) ; } }

Index/key variables: i
Accumulator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; public class GFG { static int countNum ( int [ ] arr , int n ) { int count = 0 ; Arrays . sort ( arr ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] != arr [ i + 1 ] && arr [ i ] != arr [ i + 1 ] - 1 ) count += arr [ i + 1 ] - arr [ i ] - 1 ; return count ; } static public void main ( String [ ] args ) { int [ ] arr = { 3 , 5 , 8 , 6 } ; int n = arr . length ; System . out . println ( countNum ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { static void findElementsAfterDel ( int [ ] arr , int m , int [ ] del , int n , int k ) { HashMap < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( mp . containsKey ( del [ i ] ) ) { mp . put ( del [ i ] , mp . get ( del [ i ] ) + 1 ) ; } else { mp . put ( del [ i ] , 1 ) ; } } Vector < Integer > heap = new Vector < Integer > ( ) ; for ( int i = 0 ; i < m ; ++ i ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) - 1 ) ; if ( mp . get ( arr [ i ] ) == 0 ) mp . remove ( arr [ i ] ) ; } else heap . add ( arr [ i ] ) ; } Collections . sort ( heap ) ; for ( int i = 0 ; i < k ; ++ i ) { System . out . print ( heap . get ( 0 ) + " ▁ " ) ; heap . remove ( 0 ) ; } } public static void main ( String [ ] args ) { int [ ] array = { 5 , 12 , 33 , 4 , 56 , 12 , 20 } ; int m = array . length ; int [ ] del = { 12 , 56 , 5 } ; int n = del . length ; int k = 3 ; findElementsAfterDel ( array , m , del , n , k ) ; } }

Index/key variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . HashSet ; class GFG { static int countNum ( int arr [ ] , int n ) { HashSet < Integer > s = new HashSet < > ( ) ; int count = 0 , maxm = Integer . MIN_VALUE , minm = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { s . add ( arr [ i ] ) ; if ( arr [ i ] < minm ) minm = arr [ i ] ; if ( arr [ i ] > maxm ) maxm = arr [ i ] ; } for ( int i = minm ; i <= maxm ; i ++ ) if ( ! s . contains ( i ) ) count ++ ; return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 5 , 8 , 6 } ; int n = arr . length ; System . out . println ( countNum ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int findmax ( int [ ] A ) { int r = A [ 0 ] ; for ( int i = 1 ; i < A . length ; i ++ ) r = Math . max ( r , A [ i ] ) ; return r ; } static boolean isPossible ( int [ ] A , int n , int H , int K ) { int time = 0 ; for ( int i = 0 ; i < n ; ++ i ) time += ( A [ i ] - 1 ) / K + 1 ; return time <= H ; } static int minJobSpeed ( int [ ] A , int n , int H ) { if ( H < n ) return - 1 ; int max = findmax ( A ) ; int lo = 1 , hi = max ; while ( lo < hi ) { int mi = lo + ( hi - lo ) / 2 ; if ( ! isPossible ( A , n , H , mi ) ) lo = mi + 1 ; else hi = mi ; } return lo ; } public static void main ( String [ ] args ) { int [ ] A = { 3 , 6 , 7 , 11 } ; int H = 8 ; int n = A . length ; System . out . println ( minJobSpeed ( A , n , H ) ) ; } }

Index/key variables: i
Accumulator variables: i, time
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAXN = 11 ; static int ver = 2 ; static int [ ] [ ] hashtable = new int [ ver ] [ MAXN ] ; static int [ ] pos = new int [ ver ] ; static void initTable ( ) { for ( int j = 0 ; j < MAXN ; j ++ ) for ( int i = 0 ; i < ver ; i ++ ) hashtable [ i ] [ j ] = Integer . MIN_VALUE ; } static int hash ( int function , int key ) { switch ( function ) { case 1 : return key % MAXN ; case 2 : return ( key / MAXN ) % MAXN ; } return Integer . MIN_VALUE ; } static void place ( int key , int tableID , int cnt , int n ) { if ( cnt == n ) { System . out . printf ( "%d unpositionedNEW_LINE", key); System . out . printf ( "Cycle present. REHASH.NEW_LINE"); return ; } for ( int i = 0 ; i < ver ; i ++ ) { pos [ i ] = hash ( i + 1 , key ) ; if ( hashtable [ i ] [ pos [ i ] ] == key ) return ; } if ( hashtable [ tableID ] [ pos [ tableID ] ] != Integer . MIN_VALUE ) { int dis = hashtable [ tableID ] [ pos [ tableID ] ] ; hashtable [ tableID ] [ pos [ tableID ] ] = key ; place ( dis , ( tableID + 1 ) % ver , cnt + 1 , n ) ; } else hashtable [ tableID ] [ pos [ tableID ] ] = key ; } static void printTable ( ) { System . out . printf ( "Final hash tables:NEW_LINE"); for ( int i = 0 ; i < ver ; i ++ , System . out . printf ( "NEW_LINE")) for ( int j = 0 ; j < MAXN ; j ++ ) if ( hashtable [ i ] [ j ] == Integer . MIN_VALUE ) System . out . printf ( " - ▁ " ) ; else System . out . printf ( " % d ▁ " , hashtable [ i ] [ j ] ) ; System . out . printf ( "NEW_LINE"); } static void cuckoo ( int keys [ ] , int n ) { initTable ( ) ; for ( int i = 0 , cnt = 0 ; i < n ; i ++ , cnt = 0 ) place ( keys [ i ] , 0 , cnt , n ) ; printTable ( ) ; } public static void main ( String [ ] args ) { int keys_1 [ ] = { 20 , 50 , 53 , 75 , 100 , 67 , 105 , 3 , 36 , 39 } ; int n = keys_1 . length ; cuckoo ( keys_1 , n ) ; int keys_2 [ ] = { 20 , 50 , 53 , 75 , 100 , 67 , 105 , 3 , 36 , 39 , 6 } ; int m = keys_2 . length ; cuckoo ( keys_2 , m ) ; } }

Index/key variables: MAXN, i, j, tableID, ver
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countAnomalies ( int a [ ] , int n , int k ) { Arrays . sort ( a ) ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int u = upper_bound ( a , 0 , n , a [ i ] ) ; if ( u < n && a [ u ] - a [ i ] <= k ) continue ; int s = lower_bound ( a , 0 , n , a [ i ] ) ; if ( u - s > 1 ) continue ; if ( s > 0 && a [ s - 1 ] - a [ i ] <= k ) continue ; res ++ ; } return res ; } static int lower_bound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } 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 [ ] = { 7 , 1 , 8 } , k = 5 ; int n = arr . length ; System . out . print ( countAnomalies ( arr , n , k ) ) ; } }

Index/key variables: i, middle, u
Accumulator variables: i, res
Iterator variables: i
Class/struct names: GFG