dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static boolean check ( int [ ] bananas , int mid_val , int H ) { int time = 0 ; for ( int i = 0 ; i < bananas . length ; i ++ ) { if ( bananas [ i ] % mid_val != 0 ) { time += ( ( bananas [ i ] / mid_val ) + 1 ) ; } else { time += ( bananas [ i ] / mid_val ) ; } } if ( time <= H ) { return true ; } else { return false ; } } static int minEatingSpeed ( int [ ] piles , int H ) { int start = 1 ; int end = Arrays . stream ( piles ) . max ( ) . getAsInt ( ) ; while ( start < end ) { int mid = start + ( end - start ) / 2 ; if ( ( check ( piles , mid , H ) ) == true ) { end = mid ; } else { start = mid + 1 ; } } return end ; } public static void main ( String [ ] args ) { int [ ] piles = { 30 , 11 , 23 , 4 , 20 } ; int H = 6 ; System . out . print ( minEatingSpeed ( piles , H ) ) ; } }

Index/key variables: i
Accumulator variables: i, time
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int minSumPair ( int arr [ ] , int N ) { if ( N < 5 ) { return - 1 ; } int [ ] prefixMin = new int [ N ] ; prefixMin [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N - 1 ; i ++ ) { prefixMin [ i ] = Math . min ( arr [ i ] , prefixMin [ i - 1 ] ) ; } int ans = Integer . MAX_VALUE ; for ( int i = 3 ; i < N - 1 ; i ++ ) { ans = Math . min ( ans , arr [ i ] + prefixMin [ i - 2 ] ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 2 , 4 , 6 , 3 , 7 } ; int N = arr . length ; System . out . print ( minSumPair ( arr , N ) + "NEW_LINE"); } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static long check ( long H [ ] , long A [ ] , long mid , long N , long M , long L ) { long sum = 0 ; for ( long i = 0 ; i < N ; i ++ ) { long speed = mid * A [ ( int ) i ] + H [ ( int ) i ] ; if ( speed >= L ) { sum += speed ; } } return sum ; } static long buzzTime ( long N , long M , long L , long H [ ] , long A [ ] ) { long low = 0 , high = 100000000 ; long ans = 0 ; while ( high >= low ) { long mid = low + ( high - low ) / 2 ; if ( check ( H , A , mid , N , M , L ) >= M ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } return ans ; } public static void main ( String [ ] args ) { long M = 400 , L = 120 ; long H [ ] = { 20 , 50 , 20 } ; long A [ ] = { 20 , 70 , 90 } ; long N = A . length ; System . out . println ( buzzTime ( N , M , L , H , A ) ) ; } }

Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static void findCount ( String number ) { int sum = 0 ; for ( int i = 0 ; i < number . length ( ) ; ++ i ) { sum += number . charAt ( i ) - 48 ; } int count = 0 ; for ( int i = 0 ; i < number . length ( ) ; ++ i ) { int remaining_sum = sum - ( number . charAt ( i ) - 48 ) ; for ( int j = 0 ; j <= 9 ; ++ j ) { if ( ( remaining_sum + j ) % 3 == 0 && j != number . charAt ( i ) - 48 ) { ++ count ; } } } System . out . println ( count ) ; } public static void main ( String [ ] args ) { String number = "235" ; findCount ( number ) ; } }

Accumulator variables: sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { public static boolean is_possible ( int [ ] teams , int T , int k ) { int sum = 0 ; for ( int i = 0 ; i < teams . length ; i ++ ) { sum += Math . min ( T , teams [ i ] ) ; } return ( sum >= ( T * k ) ) ; } public static int countOfTeams ( int [ ] teams_list , int N , int K ) { int lb = 0 ; double ub = 1e9 ; while ( lb <= ub ) { int mid = lb + ( int ) ( ub - lb ) / 2 ; if ( is_possible ( teams_list , mid , K ) ) { if ( ! is_possible ( teams_list , mid + 1 , K ) ) { return mid ; } else { lb = mid + 1 ; } } else { ub = mid - 1 ; } } return 0 ; } public static void main ( String args [ ] ) { int [ ] arr = { 2 , 3 , 4 } ; int K = 2 ; int N = arr . length ; System . out . println ( countOfTeams ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void minimumOperations ( int arr [ ] , int N ) { int mx = 0 , pos = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= mx ) { mx = arr [ i ] ; pos = i ; } } System . out . println ( ( mx - 1 ) * N + pos + 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 0 , 2 } ; int N = arr . length ; minimumOperations ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static long n , m , k , l , r , i ; static boolean check ( long v , long [ ] a ) { long tec = 0 , ans = 0 ; long [ ] b = new long [ ( int ) ( n + k + 1 ) ] ; for ( int i = 0 ; i < n ; i ++ ) { tec -= b [ i ] ; if ( a [ i ] + tec < v ) { long mov = v - a [ i ] - tec ; ans = ans + mov ; tec += mov ; b [ i + ( int ) k ] = mov ; } } return ans <= m ; } static long FindLargest ( long [ ] a ) { l = 1 ; r = ( long ) Math . pow ( 10 , 10 ) ; while ( r - l > 0 ) { long tm = ( l + r + 1 ) / 2 ; if ( check ( tm , a ) ) l = tm ; else r = tm - 1 ; } return l ; } public static void main ( String [ ] args ) { long [ ] a = { 2 , 2 , 2 , 2 , 1 , 1 } ; m = 2 ; k = 3 ; n = a . length ; System . out . println ( FindLargest ( a ) ) ; } }

Index/key variables: i
Accumulator variables: i, tec
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = null ; right = null ; } } class Solution { public static ArrayList < Integer > findSteps ( Node root , int data ) { ArrayList < Integer > steps = new ArrayList < Integer > ( ) ; while ( data != 1 ) { if ( data / 2.0 > data / 2 ) { steps . add ( 1 ) ; } else { steps . add ( - 1 ) ; } int parent = data / 2 ; data = parent ; } Collections . reverse ( steps ) ; return steps ; } public static boolean findKey ( Node root , int data ) { ArrayList < Integer > steps = findSteps ( root , data ) ; for ( Integer cur_step : steps ) { if ( cur_step == - 1 ) { if ( root . left == null ) return false ; root = root . left ; } else { if ( root . right == null ) return false ; root = root . right ; } } return true ; } 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 . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 9 ) ; root . left . right . left = new Node ( 10 ) ; System . out . println ( findKey ( root , 7 ) ) ; } }

Iterator variables: cur_step
Class/struct names: Node, Solution
Java program:
import java . io . * ; class GFG { static int largestAltitude ( int L , int B ) { if ( L > B ) { int t = L ; L = B ; B = t ; } int low = 0 , high = L ; int res = 0 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( mid <= ( B / 2 ) ) { res = mid ; low = mid + 1 ; } else high = mid - 1 ; } return res ; } public static void main ( String [ ] args ) { int L = 3 ; int B = 4 ; System . out . print ( largestAltitude ( L , B ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void printFreq ( int arr [ ] , int N ) { int freq = 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) { freq ++ ; } else { System . out . println ( " Frequency ▁ of ▁ " + arr [ i - 1 ] + " ▁ is : ▁ " + freq ) ; freq = 1 ; } } System . out . println ( " Frequency ▁ of ▁ " + arr [ N - 1 ] + " ▁ is : ▁ " + freq ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 } ; int N = arr . length ; printFreq ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: freq, i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static boolean isMaximumMedian ( int arr [ ] [ ] , int N , int K , int mid ) { int [ ] [ ] Pre = new int [ N + 5 ] [ N + 5 ] ; for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) { Pre [ i + 1 ] [ j + 1 ] = Pre [ i + 1 ] [ j ] + Pre [ i ] [ j + 1 ] - Pre [ i ] [ j ] ; if ( arr [ i ] [ j ] <= mid ) Pre [ i + 1 ] [ j + 1 ] ++ ; } } int required = ( K * K + 1 ) / 2 ; boolean flag = false ; for ( int i = K ; i <= N ; ++ i ) { for ( int j = K ; j <= N ; ++ j ) { int X = Pre [ i ] [ j ] - Pre [ i - K ] [ j ] - Pre [ i ] [ j - K ] + Pre [ i - K ] [ j - K ] ; if ( X < required ) flag = true ; } } return flag ; } static int maximumMedian ( int arr [ ] [ ] , int N , int K ) { int low = 0 , high = ( int ) 1e9 ; while ( low < high ) { int mid = low + ( high - low ) / 2 ; if ( isMaximumMedian ( arr , N , K , mid ) ) { low = mid + 1 ; } else { high = mid ; } } return low ; } public static void main ( String args [ ] ) { int [ ] [ ] arr = { { 1 , 5 , 12 } , { 6 , 7 , 11 } , { 8 , 9 , 10 } } ; int N = arr . length ; int K = 2 ; System . out . print ( maximumMedian ( arr , N , K ) ) ; } }

Index/key variables: i, j
Iterator variables: i, j
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void findMinDays ( int arr [ ] , int R [ ] , int N , int X , int K ) { int low = 0 , high = X ; int minDays = - 1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int temp = arr [ i ] + R [ i ] * mid ; if ( temp >= K ) { sum += temp ; } } if ( sum >= X ) { minDays = mid ; high = mid - 1 ; } else { low = mid + 1 ; } } System . out . println ( minDays ) ; } public static void main ( String [ ] args ) { int X = 100 , K = 45 ; int arr [ ] = { 2 , 5 , 2 , 6 } ; int R [ ] = { 10 , 13 , 15 , 12 } ; int N = arr . length ; findMinDays ( arr , R , N , X , K ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int getPairsCount ( int a [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( ( a [ i ] * a [ j ] ) == Math . abs ( i - j ) ) count ++ ; } } return count ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 1 , 2 , 4 } ; int N = arr . length ; System . out . print ( getPairsCount ( arr , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . lang . * ; import java . util . * ; class GFG { static String lexicographicallySmallestString ( String S , int N ) { int LastZe = - 1 ; String ans = " " ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( S . charAt ( i ) == '0' ) { LastZe = i ; break ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( i <= LastZe && S . charAt ( i ) == '0' ) ans += S . charAt ( i ) ; else if ( i > LastZe ) ans += S . charAt ( i ) ; } return ans ; } public static void main ( String [ ] args ) { String S = "11001101" ; int N = S . length ( ) ; System . out . println ( lexicographicallySmallestString ( S , N ) ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void numberofBoxes ( int W , int B , int O ) { int low = 0 , high = Math . min ( W , B ) ; int ans = 0 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( ( ( W >= mid ) && ( B >= mid ) ) && ( ( W - mid ) + ( B - mid ) + O ) >= mid ) { ans = mid ; low = mid + 1 ; } else high = mid - 1 ; } System . out . println ( ans ) ; } public static void main ( String args [ ] ) { int W = 3 , B = 3 , O = 1 ; numberofBoxes ( W , B , O ) ; } }

Class/struct names: GFG
Java program:
public class MyClass { public static int minSwaps ( int N , int M , int A [ ] [ ] , int B [ ] [ ] ) { int count01 = 0 ; int count10 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( A [ i ] [ j ] != B [ i ] [ j ] ) { if ( A [ i ] [ j ] == 1 ) count10 ++ ; else count01 ++ ; } } } if ( count01 == count10 ) return count01 ; else return - 1 ; } public static void main ( String args [ ] ) { int [ ] [ ] A = { { 1 , 1 , 0 } , { 0 , 0 , 1 } , { 0 , 1 , 0 } } ; int [ ] [ ] B = { { 0 , 0 , 1 } , { 0 , 1 , 0 } , { 1 , 1 , 0 } } ; int N = A . length ; int M = B [ 0 ] . length ; System . out . println ( minSwaps ( N , M , A , B ) ) ; } }

Index/key variables: i, j
Accumulator variables: count01, count10, i, j
Iterator variables: i, j
Class/struct names: MyClass
Java program:
public class GFG { static int Count ( int N , int K ) { if ( K == 0 ) return 0 ; int sum = 0 ; int res = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += i ; if ( sum <= K ) res ++ ; else break ; } return res ; } public static void main ( String args [ ] ) { int N = 6 , K = 14 ; System . out . println ( Count ( N , K ) ) ; } }

Accumulator variables: i, res, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String removeLastOccurrence ( String S , String W , int N , int M ) { char [ ] ch = S . toCharArray ( ) ; if ( M > N ) return S ; for ( int i = N - M ; i >= 0 ; i -- ) { int flag = 0 ; for ( int j = 0 ; j < M ; j ++ ) { if ( ch [ j + i ] != W . charAt ( j ) ) { flag = 1 ; break ; } } if ( flag == 0 ) { for ( int j = i ; j < N - M ; j ++ ) ch [ j ] = ch [ j + M ] ; break ; } } char [ ] chh = new char [ N - M ] ; for ( int i = 0 ; i < N - M ; i ++ ) { chh [ i ] = ch [ i ] ; } return String . valueOf ( chh ) ; } public static void main ( String [ ] args ) { String S = " This ▁ is ▁ GeeksForGeeks " ; String W = " Geeks " ; int N = S . length ( ) ; int M = W . length ( ) ; System . out . print ( removeLastOccurrence ( S , W , N , M ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static void maximumIndices ( int arr [ ] , int N ) { int [ ] temp = new int [ N ] ; int maxIndices = ( N - 1 ) / 2 ; Arrays . sort ( arr ) ; for ( int i = 0 ; i < maxIndices ; i ++ ) { temp [ 2 * i + 1 ] = arr [ i ] ; } int j = 0 ; for ( int i = maxIndices ; i < N ; ) { if ( temp [ j ] == 0 ) { temp [ j ] = arr [ i ] ; i ++ ; } j ++ ; } for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( temp [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = 4 ; maximumIndices ( arr , N ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int repeatingElement ( int arr [ ] , int N ) { int M = 0 , sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; M = Math . max ( M , arr [ i ] ) ; } int sum1 = M * ( M + 1 ) / 2 ; int ans = ( sum - sum1 ) / ( N - M ) ; return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 6 , 4 , 3 , 1 , 5 , 2 } ; int N = arr . length ; System . out . println ( repeatingElement ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int calculateMax ( int N , int M , int K ) { int ans = - 1 ; int low = 0 , high = M ; while ( low <= high ) { int mid = ( low + high ) / 2 ; int val = 0 ; int L = K - 1 ; int R = N - K ; val += mid ; if ( mid >= L ) { val += ( L ) * ( 2 * mid - L - 1 ) / 2 ; } else { val += mid * ( mid - 1 ) / 2 + ( L - mid ) ; } if ( mid >= R ) { val += ( R ) * ( 2 * mid - R - 1 ) / 2 ; } else { val += mid * ( mid - 1 ) / 2 + ( R - mid ) ; } if ( val <= M ) { ans = Math . max ( ans , mid ) ; low = mid + 1 ; } else high = mid - 1 ; } return ans ; } public static void main ( String [ ] args ) { int N = 7 , M = 100 , K = 6 ; System . out . println ( calculateMax ( N , M , K ) ) ; } }

Accumulator variables: val
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int ans = 0 ; @ SuppressWarnings ( " unchecked " ) static Vector < Integer > edges [ ] = new Vector [ 100000 ] ; static void Add_edge ( int u , int v ) { edges [ u ] . add ( v ) ; edges [ v ] . add ( u ) ; } static void minTimeToColor ( int node , int parent , int arrival_time ) { int current_time = 0 ; for ( int x = 0 ; x < edges [ node ] . size ( ) ; x ++ ) { if ( edges [ node ] . get ( x ) != parent ) { ++ current_time ; if ( current_time == arrival_time ) ++ current_time ; ans = Math . max ( ans , current_time ) ; minTimeToColor ( edges [ node ] . get ( x ) , node , current_time ) ; } } } public static void main ( String [ ] args ) { for ( int i = 0 ; i < edges . length ; i ++ ) edges [ i ] = new Vector < Integer > ( ) ; int A [ ] [ ] = { { 1 , 2 } , { 2 , 3 } , { 3 , 4 } } ; for ( int i = 0 ; i < 3 ; i ++ ) { Add_edge ( A [ i ] [ 0 ] , A [ i ] [ 1 ] ) ; } minTimeToColor ( 1 , - 1 , 0 ) ; System . out . print ( ans + "NEW_LINE"); } }

Index/key variables: i, node, u, v
Accumulator variables: i, x
Iterator variables: i, x
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; public class GFG { public static int largestNum ( int [ ] arr ) { int res = 0 ; Arrays . sort ( arr ) ; int l = 0 , r = arr . length - 1 ; while ( l < r ) { int sum = arr [ l ] + arr [ r ] ; if ( sum == 0 ) { res = Math . max ( res , Math . max ( arr [ l ] , arr [ r ] ) ) ; return res ; } else if ( sum < 0 ) { l ++ ; } else { r -- ; } } return res ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 2 , - 2 , 5 , - 3 } ; System . out . println ( largestNum ( arr ) ) ; } }

Index/key variables: l, r
Accumulator variables: l, r
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findLarger ( int arr [ ] , int n ) { int mid = ( n + 1 ) / 2 ; int mx = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; int count [ ] = new int [ mx + 1 ] ; for ( int i = 0 ; i < mx + 1 ; i ++ ) { count [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) { count [ arr [ i ] ] ++ ; } for ( int i = mx ; i >= 0 ; i -- ) { while ( count [ i ] > 0 ) { count [ i ] -- ; mid -- ; System . out . print ( i + " ▁ " ) ; if ( mid == 0 ) break ; } if ( mid == 0 ) break ; } } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 4 , 2 , 8 , 9 } ; int N = arr . length ; findLarger ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, mid
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static double probability ( int [ ] arr1 , int [ ] arr2 ) { int N = arr1 . length ; int M = arr2 . length ; double res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int y = 0 ; for ( int j = 0 ; j < M ; j ++ ) { if ( arr2 [ j ] > arr1 [ i ] ) y ++ ; } res += y ; } res = ( double ) res / ( double ) ( N * M ) ; return res ; } public static void main ( String [ ] args ) { int [ ] arr1 = { 5 , 2 , 6 , 1 } ; int [ ] arr2 = { 1 , 6 , 10 , 1 } ; System . out . println ( probability ( arr1 , arr2 ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, res, y
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static double probability ( int [ ] arr1 , int [ ] arr2 ) { int N = arr1 . length ; int M = arr2 . length ; double res = 0 ; Arrays . sort ( arr2 ) ; for ( int i = 0 ; i < N ; i ++ ) { int y = countGreater ( arr2 , arr1 [ i ] ) ; res += y ; } res = ( double ) res / ( double ) ( N * M ) ; return res ; } static int countGreater ( int [ ] arr , int k ) { int n = arr . length ; 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 [ ] arr1 = { 5 , 2 , 6 , 1 } ; int [ ] arr2 = { 1 , 6 , 10 , 1 } ; System . out . println ( probability ( arr1 , arr2 ) ) ; } }

Index/key variables: i, m
Accumulator variables: i, res
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class MyClass { static void minCost ( char arr [ ] [ ] , int A , int B ) { int n = arr . length ; int m = arr [ 0 ] . length ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( arr [ i ] [ j ] == ' * ' ) continue ; if ( j == m - 1 ) ans += A ; else { if ( arr [ i ] [ j + 1 ] == ' . ' ) { ans += Math . min ( 2 * A , B ) ; j ++ ; } else ans += A ; } } } System . out . println ( ans ) ; } public static void main ( String args [ ] ) { char [ ] [ ] arr = { { ' . ' , ' . ' , ' * ' } , { ' . ' , ' * ' , ' * ' } } ; int A = 2 , B = 10 ; minCost ( arr , A , B ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: MyClass
Java program:
import java . util . Vector ; class GFG { static void countInversions ( int arr [ ] , int n ) { Vector < Integer > v = new Vector < > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { v . add ( i ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int itr = v . indexOf ( arr [ i ] ) ; ans += itr ; v . remove ( itr ) ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 1 , 5 , 4 } ; int n = arr . length ; countInversions ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findPairs ( int A , int B ) { for ( int i = 1 ; i <= B ; i ++ ) { int y = A ^ i ; if ( y > 0 && ( i y ) == B ) { System . out . println ( i + " ▁ " + y ) ; } } } public static void main ( String [ ] args ) { int A = 8 , B = 10 ; findPairs ( A , B ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int binarysearch ( int array [ ] , int element ) { int left = 1 ; int right = array . length - 1 ; while ( left <= right ) { int mid = ( int ) ( left + right / 2 ) ; if ( array [ mid ] == element ) { return mid ; } if ( mid - 1 > 0 && array [ mid ] > element && array [ mid - 1 ] < element ) { return mid ; } else if ( array [ mid ] < element ) { left = mid + 1 ; } else { right = mid - 1 ; } } return 1 ; } static void countDistinct ( int arr [ ] , int L , int R ) { int count = 0 ; int pref [ ] = new int [ arr . length + 1 ] ; for ( int i = 1 ; i <= arr . length ; ++ i ) { count += arr [ i - 1 ] ; pref [ i ] = count ; } int left = binarysearch ( pref , L ) ; int right = binarysearch ( pref , R ) ; System . out . println ( ( right - left ) + 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 6 , 7 , 1 , 8 } ; int L = 3 ; int R = 7 ; countDistinct ( arr , L , R ) ; } }

Index/key variables: i, mid
Accumulator variables: count
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { public static void countSubstrings ( String s ) { int n = s . length ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int cnt = 0 ; for ( int j = i ; j < n ; j ++ ) { if ( s . charAt ( j ) == ' a ' ) cnt ++ ; else if ( s . charAt ( j ) == ' c ' ) cnt -- ; if ( cnt > 0 ) { ans ++ ; } } } System . out . println ( ans ) ; } public static void main ( String args [ ] ) { String S = " abccaab " ; countSubstrings ( S ) ; } }

Accumulator variables: ans, cnt, i, j
Iterator variables: i, j
Class/struct names: GFG