dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . Scanner ; import java . io . * ; class GFG { static int countMaxSumPairs ( int a [ ] , int n ) { int first = Integer . MIN_VALUE , second = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > first ) { second = first ; first = a [ i ] ; } else if ( a [ i ] > second && a [ i ] != first ) second = a [ i ] ; } int cnt1 = 0 , cnt2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == first ) cnt1 ++ ; if ( a [ i ] == second ) cnt2 ++ ; } if ( cnt1 == 1 ) return cnt2 ; if ( cnt1 > 1 ) return cnt1 * ( cnt1 - 1 ) / 2 ; return 0 ; } static float findMaxSumProbability ( int a [ ] , int n ) { int total = n * ( n - 1 ) / 2 ; int max_sum_pairs = countMaxSumPairs ( a , n ) ; return ( float ) max_sum_pairs / ( float ) total ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 2 , 3 } ; int n = a . length ; ; System . out . println ( findMaxSumProbability ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: cnt1, cnt2, i
Iterator variables: i
Class/struct names: GFG
Java program:
int sum [ ] = new int [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) dp [ 1 ] [ i ] = sum [ i ] ; and using it to calculate the result as : best = Math . min ( best , Math . max ( dp [ i - 1 ] [ p ] , sum [ j ] - sum [ p ] ) ) ;

Index/key variables: i, j, p
Accumulator variables: i
Iterator variables: i
Java program:
for ( int i = k - 1 ; i <= n ; i ++ ) best = Math . min ( best , Math . max ( partition ( arr , i , k - 1 ) , sum ( arr , i , n - 1 ) ) ) ;

Accumulator variables: i
Iterator variables: i
Java program:
class GFG { static int findS ( int s ) { int sum = 0 ; for ( int n = 1 ; sum < s ; n ++ ) { sum += n ; if ( sum == s ) return n ; } return - 1 ; } public static void main ( String [ ] args ) { int s = 15 ; int n = findS ( s ) ; if ( n == - 1 ) System . out . println ( " - 1" ) ; else System . out . println ( n ) ; } }

Accumulator variables: n, sum
Iterator variables: n
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int isvalid ( int s ) { double k = ( - 1.0 + Math . sqrt ( 1 + 8 * s ) ) / 2 ; if ( Math . ceil ( k ) == Math . floor ( k ) ) return ( int ) k ; else return - 1 ; } public static void main ( String [ ] args ) { int s = 15 ; System . out . print ( isvalid ( s ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static int calcSafe ( int pos ) { int j = pos % 10 ; int i = pos / 10 ; int dis_11 = Math . min ( Math . abs ( 1 - i ) , Math . abs ( 1 - j ) ) ; int dis_18 = Math . min ( Math . abs ( 1 - i ) , Math . abs ( 8 - j ) ) ; int dis_81 = Math . min ( Math . abs ( 8 - i ) , Math . abs ( 1 - j ) ) ; int dis_88 = Math . min ( Math . abs ( 8 - i ) , Math . abs ( 8 - j ) ) ; int sum = dis_11 + dis_18 + dis_81 + dis_88 + 1 ; return ( 64 - sum ) ; } public static void main ( String [ ] args ) { int pos = 34 ; System . out . print ( " Safe ▁ Positions ▁ = ▁ " + calcSafe ( pos ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int count_crossline ; static void merge ( int arr [ ] , int l , int m , int r ) { int i , j , k ; int n1 = m - l + 1 ; int n2 = r - m ; int [ ] L = new int [ n1 ] ; int [ ] R = new int [ n2 ] ; for ( i = 0 ; i < n1 ; i ++ ) { L [ i ] = arr [ l + i ] ; } for ( j = 0 ; j < n2 ; j ++ ) { R [ j ] = arr [ m + 1 + j ] ; } while ( i < n1 && j < n2 ) { if ( L [ i ] <= R [ j ] ) { arr [ k ] = L [ i ] ; i ++ ; } else { arr [ k ] = R [ j ] ; count_crossline += ( n1 - i ) ; j ++ ; } k ++ ; } while ( i < n1 ) { arr [ k ] = L [ i ] ; i ++ ; k ++ ; } while ( j < n2 ) { arr [ k ] = R [ j ] ; j ++ ; k ++ ; } } static void mergeSort ( int arr [ ] , int l , int r ) { if ( l < r ) { int m = l + ( r - l ) / 2 ; mergeSort ( arr , l , m ) ; mergeSort ( arr , m + 1 , r ) ; merge ( arr , l , m , r ) ; } } static int countCrossLine ( int arr [ ] , int n ) { mergeSort ( arr , 0 , n - 1 ) ; return count_crossline ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 11 , 13 , 5 , 6 , 7 } ; int n = arr . length ; System . out . println ( countCrossLine ( arr , n ) ) ; } }

Index/key variables: i, j, k, n1, n2
Accumulator variables: count_crossline, i, j, k
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int getCount ( int arr [ ] , int n , int num1 , int num2 ) { int i = 0 ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == num1 ) break ; if ( i >= n - 1 ) return 0 ; int j ; for ( j = n - 1 ; j >= i + 1 ; j -- ) if ( arr [ j ] == num2 ) break ; if ( j == i ) return 0 ; return ( j - i - 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 5 , 7 , 6 , 4 , 9 , 12 , 4 , 8 } ; int n = arr . length ; int num1 = 5 , num2 = 4 ; System . out . println ( getCount ( arr , n , num1 , num2 ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int ROW = 3 ; static int COL = 5 ; static int minTotalDistance ( int grid [ ] [ ] ) { if ( ROW == 0 COL == 0 ) return 0 ; Vector < Integer > vertical = new Vector < Integer > ( ) ; Vector < Integer > horizontal = new Vector < Integer > ( ) ; for ( int i = 0 ; i < ROW ; i ++ ) { for ( int j = 0 ; j < COL ; j ++ ) { if ( grid [ i ] [ j ] == 1 ) { vertical . add ( i ) ; horizontal . add ( j ) ; } } } Collections . sort ( vertical ) ; Collections . sort ( horizontal ) ; int size = vertical . size ( ) / 2 ; int x = vertical . get ( size ) ; int y = horizontal . get ( size ) ; int distance = 0 ; for ( int i = 0 ; i < ROW ; i ++ ) for ( int j = 0 ; j < COL ; j ++ ) if ( grid [ i ] [ j ] == 1 ) distance += Math . abs ( x - i ) + Math . abs ( y - j ) ; return distance ; } public static void main ( String [ ] args ) { int grid [ ] [ ] = { { 1 , 0 , 1 , 0 , 1 } , { 0 , 1 , 0 , 0 , 0 } , { 0 , 1 , 1 , 0 , 0 } } ; System . out . println ( minTotalDistance ( grid ) ) ; } }

Index/key variables: i, j
Accumulator variables: distance, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class Test { static int sumOfDigit ( int K ) { int sod = 0 ; while ( K != 0 ) { sod += K % 10 ; K /= 10 ; } return sod ; } static int totalNumbersWithSpecificDifference ( int N , int diff ) { int low = 1 , high = N ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( mid - sumOfDigit ( mid ) < diff ) low = mid + 1 ; else high = mid - 1 ; } return ( N - high ) ; } public static void main ( String args [ ] ) { int N = 13 ; int diff = 2 ; System . out . println ( totalNumbersWithSpecificDifference ( N , diff ) ) ; } }

Accumulator variables: K, sod
Class/struct names: Test
Java program:
class GFG { static int getRandom ( int x , int y ) { return ( int ) ( x + Math . random ( ) * 10 % ( y - x + 1 ) ) ; } static int randomizedBinarySearch ( int arr [ ] , int l , int r , int x ) { while ( l <= r ) { int m = getRandom ( l , r ) ; if ( arr [ m ] == x ) return m ; if ( arr [ m ] < x ) l = m + 1 ; else r = m - 1 ; } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 10 , 40 } ; int n = arr . length ; int x = 10 ; int result = randomizedBinarySearch ( arr , 0 , n - 1 , x ) ; if ( result == - 1 ) System . out . printf ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " ) ; else System . out . printf ( " Element ▁ is ▁ present ▁ at ▁ index ▁ % d " , result ) ; } }

Index/key variables: m
Class/struct names: GFG
Java program:
class Test { static int countBuildings ( int arr [ ] , int n ) { int count = 1 ; int curr_max = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > curr_max arr [ i ] == curr_max ) { count ++ ; curr_max = arr [ i ] ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 4 , 8 , 2 , 9 } ; System . out . println ( countBuildings ( arr , arr . length ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: Test
Java program:
class GFG { static int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ; return n ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 2 , 4 , 6 , 8 , 10 , 12 , 13 } ; int arr2 [ ] = { 2 , 4 , 6 , 8 , 10 , 12 } ; int n = arr2 . length ; System . out . println ( findExtra ( arr1 , arr2 , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) { int index = n ; int left = 0 , right = n - 1 ; while ( left <= right ) { int mid = ( left + right ) / 2 ; if ( arr2 [ mid ] == arr1 [ mid ] ) left = mid + 1 ; else { index = mid ; right = mid - 1 ; } } return index ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 2 , 4 , 6 , 8 , 10 , 12 , 13 } ; int arr2 [ ] = { 2 , 4 , 6 , 8 , 10 , 12 } ; int n = arr2 . length ; System . out . println ( findExtra ( arr1 , arr2 , n ) ) ; } }

Index/key variables: mid
Class/struct names: GFG
Java program:
class GFG { public static int computeCost ( int arr [ ] , int N , int X ) { int cost = 0 ; for ( int i = 0 ; i < N ; i ++ ) cost += Math . abs ( arr [ i ] - X ) ; return cost ; } public static int minCostToMakeElementEqual ( int arr [ ] , int N ) { int low , high ; low = high = arr [ 0 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( low > arr [ i ] ) low = arr [ i ] ; if ( high < arr [ i ] ) high = arr [ i ] ; } while ( ( high - low ) > 2 ) { int mid1 = low + ( high - low ) / 3 ; int mid2 = high - ( high - low ) / 3 ; int cost1 = computeCost ( arr , N , mid1 ) ; int cost2 = computeCost ( arr , N , mid2 ) ; if ( cost1 < cost2 ) high = mid2 ; else low = mid1 ; } return computeCost ( arr , N , ( low + high ) / 2 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 100 , 101 } ; int N = arr . length ; System . out . println ( minCostToMakeElementEqual ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: cost, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void minJumps ( int [ ] w , int [ ] l , int n ) { if ( n == 1 ) { System . out . print ( 0 ) ; return ; } int ans = 0 ; HashMap < Integer , Integer > pos = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Integer > jump = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Boolean > filled = new HashMap < Integer , Boolean > ( ) ; int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( pos . containsKey ( w [ i ] ) ) pos . put ( w [ i ] , i ) ; else pos . put ( w [ i ] , i ) ; if ( filled . containsKey ( w [ i ] ) ) filled . put ( i , true ) ; else filled . put ( i , true ) ; if ( jump . containsKey ( w [ i ] ) ) jump . put ( w [ i ] , l [ i ] ) ; else jump . put ( w [ i ] , l [ i ] ) ; a [ i ] = w [ i ] ; } Arrays . sort ( a ) ; for ( int curr = 1 ; curr < n ; curr ++ ) { int currElementPos = pos . get ( a [ curr ] ) ; int prevElementPos = pos . get ( a [ curr - 1 ] ) ; if ( currElementPos > prevElementPos ) continue ; while ( currElementPos <= prevElementPos || filled . containsKey ( currElementPos ) && filled . containsKey ( currElementPos ) ) { currElementPos += jump . get ( a [ curr ] ) ; ans ++ ; } if ( pos . containsKey ( a [ curr ] ) ) pos . put ( a [ curr ] , currElementPos ) ; else pos . put ( a [ curr ] , currElementPos ) ; if ( filled . containsKey ( currElementPos ) ) filled . put ( currElementPos , true ) ; else filled . put ( currElementPos , true ) ; } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int [ ] W = { 2 , 1 , 4 , 3 } ; int [ ] L = { 4 , 1 , 2 , 4 } ; int N = W . length ; minJumps ( W , L , N ) ; } }

Index/key variables: curr, i, n
Accumulator variables: ans, curr, currElementPos, i
Iterator variables: curr, i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void check ( int arr [ ] , int n ) { for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i - 1 ] >= ( i - 1 ) ) { int p = arr [ i - 1 ] - ( i - 1 ) ; arr [ i ] += p ; arr [ i - 1 ] -= p ; } } for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] <= arr [ i - 1 ] ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 2 , 7 , 6 } ; int N = arr . length ; check ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int keyFunc ( int n ) { int rev = 0 ; while ( n > 0 ) { rev = rev << 1 ; if ( ( n & 1 ) == 1 ) rev = rev ^ 1 ; n = n >> 1 ; } return rev ; } static int [ ] [ ] getNew ( int arr [ ] ) { int ans [ ] [ ] = new int [ arr . length ] [ 2 ] ; for ( int i = 0 ; i < arr . length ; i ++ ) ans [ i ] = new int [ ] { keyFunc ( arr [ i ] ) , arr [ i ] } ; return ans ; } static int [ ] getArr ( int [ ] [ ] arr ) { int ans [ ] = new int [ arr . length ] ; int idx = 0 ; for ( int i [ ] : arr ) ans [ idx ++ ] = i [ 1 ] ; return ans ; } static void sortArray ( int arr [ ] ) { int [ ] [ ] newArr = getNew ( arr ) ; Arrays . sort ( newArr , ( a , b ) -> { if ( Integer . compare ( a [ 0 ] , b [ 0 ] ) == 0 ) return Integer . compare ( a [ 1 ] , b [ 1 ] ) ; return Integer . compare ( a [ 0 ] , b [ 0 ] ) ; } ) ; arr = getArr ( newArr ) ; int n = arr . length ; System . out . print ( " [ " ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) System . out . print ( arr [ i ] + " , ▁ " ) ; System . out . print ( arr [ n - 1 ] + " ] " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 43 , 52 , 61 , 41 } ; sortArray ( arr ) ; } }

Index/key variables: i
Accumulator variables: i, idx
Iterator variables: i
Class/struct names: GFG
Java program:
import java . lang . * ; import java . util . * ; class GFG { static void minimumSize ( int arr [ ] , int N , int K ) { Arrays . sort ( arr ) ; reverse ( arr ) ; if ( count ( arr , 0 ) == N ) System . out . println ( 0 ) ; else if ( K >= N ) System . out . println ( 1 ) ; else System . out . println ( arr [ K ] ) ; } static void reverse ( int [ ] a ) { int i , k , t ; int n = a . length ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } } static int count ( int [ ] a , int n ) { int freq = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] == n ) freq ++ ; } return freq ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 8 , 2 } ; int K = 2 ; int N = arr . length ; minimumSize ( arr , N , K ) ; } }

Index/key variables: K, i
Accumulator variables: freq, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static void isPossibleToSort ( int arr [ ] , int N ) { int idx = - 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == 1 && arr [ i - 1 ] == 1 ) { idx = i ; break ; } } if ( idx == - 1 ) { System . out . println ( " YES " ) ; return ; } for ( int i = idx + 1 ; i < N ; i ++ ) { if ( arr [ i ] == 0 && arr [ i - 1 ] == 0 ) { System . out . println ( " NO " ) ; return ; } } System . out . println ( " YES " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 1 , 0 , 1 , 1 , 0 } ; int N = arr . length ; isPossibleToSort ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxConsecutiveRope ( int ropes [ ] , int N ) { int curSize = 0 ; Arrays . sort ( ropes ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( ropes [ i ] <= curSize + 1 ) { curSize = curSize + ropes [ i ] ; } else break ; } return curSize ; } public static void main ( String [ ] args ) { int N = 5 ; int ropes [ ] = { 1 , 2 , 7 , 1 , 1 } ; System . out . println ( maxConsecutiveRope ( ropes , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static int maxRanges ( Integer arr [ ] [ ] , int N ) { Arrays . sort ( arr , ( a , b ) -> { if ( a [ 0 ] . equals ( b [ 0 ] ) ) return Integer . compare ( a [ 1 ] , b [ 1 ] ) ; return Integer . compare ( a [ 0 ] , b [ 0 ] ) ; } ) ; int count = 1 ; Integer prev [ ] = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { Integer last [ ] = arr [ i - 1 ] ; Integer current [ ] = arr [ i ] ; if ( last [ 0 ] == current [ 0 ] && last [ 1 ] == current [ 1 ] && current [ 1 ] == current [ 0 ] ) continue ; int start = Math . max ( prev [ 0 ] , current [ 0 ] - 1 ) ; int end = Math . max ( prev [ 1 ] , current [ 1 ] ) ; if ( end - start > 0 ) { prev [ 0 ] = 1 + start ; prev [ 1 ] = end ; count ++ ; } } return count ; } public static void main ( String [ ] args ) { Integer range [ ] [ ] = { { 1 , 4 } , { 4 , 4 } , { 2 , 2 } , { 3 , 4 } , { 1 , 1 } } ; int N = range . length ; System . out . print ( maxRanges ( range , N ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int i , start , end ; static boolean adjust ( String S ) { int N = S . length ( ) ; start = i - 1 ; while ( i < N && S . charAt ( i ) < S . charAt ( i - 1 ) ) { i ++ ; } end = i - 1 ; if ( start <= 0 && i >= N ) return true ; if ( start >= 1 && i <= N ) { return ( S . charAt ( end ) >= S . charAt ( start - 1 ) && S . charAt ( start ) <= S . charAt ( i ) ) ; } if ( start >= 1 ) { return S . charAt ( end ) >= S . charAt ( start - 1 ) ; } if ( i < N ) { return S . charAt ( start ) <= S . charAt ( i ) ; } return false ; } static void isPossible ( String S , int N ) { start = - 1 ; end = - 1 ; boolean flag = true ; for ( i = 1 ; i < N ; i ++ ) { if ( S . charAt ( i ) < S . charAt ( i - 1 ) ) { if ( flag ) { if ( adjust ( S ) == false ) { System . out . println ( - 1 ) ; return ; } flag = false ; } else { System . out . println ( - 1 ) ; return ; } } } if ( start == - 1 ) { start = end = 1 ; } System . out . println ( start + " ▁ " + end ) ; } public static void main ( String [ ] args ) { String S = " abcyxuz " ; int N = S . length ( ) ; isPossible ( S , N ) ; } }

Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static int maximizedCapital ( int K , int W , int profits [ ] , int capital [ ] ) { PriorityQueue < Integer > pq = new PriorityQueue < > ( Collections . reverseOrder ( ) ) ; ArrayList < int [ ] > v = new ArrayList < > ( ) ; for ( int i = 0 ; i < capital . length ; i ++ ) { v . add ( new int [ ] { capital [ i ] , i } ) ; } Collections . sort ( v , ( a , b ) -> { if ( a [ 0 ] != b [ 0 ] ) return a [ 0 ] - b [ 0 ] ; return a [ 1 ] - b [ 1 ] ; } ) ; int j = 0 ; while ( K != 0 ) { while ( j < capital . length && v . get ( j ) [ 0 ] <= W ) { pq . add ( profits [ v . get ( j ) [ 1 ] ] ) ; j ++ ; } if ( ! pq . isEmpty ( ) ) { W = W + pq . peek ( ) ; pq . poll ( ) ; } K -- ; } return W ; } public static void main ( String [ ] args ) { int K = 2 ; int W = 0 ; int P [ ] = { 1 , 2 , 3 } ; int C [ ] = { 0 , 1 , 1 } ; System . out . println ( maximizedCapital ( K , W , P , C ) ) ; } }

Index/key variables: i
Accumulator variables: K, i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int maximumSum ( int arr [ ] , int S [ ] , int N , int K ) { int ans = 0 ; Arrays . sort ( arr ) ; for ( int i = 0 ; i < N / 2 ; i ++ ) { int temp = arr [ i ] ; arr [ i ] = arr [ N - 1 - i ] ; arr [ N - 1 - i ] = temp ; } for ( int i = 0 ; i < K ; i ++ ) ans += arr [ i ] ; Arrays . sort ( S ) ; for ( int i = 0 ; i < K ; i ++ ) { if ( S [ i ] == 1 ) ans += arr [ i ] ; S [ i ] -- ; } int counter = K - 1 ; for ( int i = 0 ; i < K ; i ++ ) { counter = counter + S [ i ] ; if ( S [ i ] != 0 ) ans += arr [ counter ] ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 13 , 7 , 17 } ; int S [ ] = { 1 , 3 } ; int N = arr . length ; int K = S . length ; System . out . println ( maximumSum ( arr , S , N , K ) ) ; } }

Index/key variables: counter, i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int binaryToDecimal ( String n ) { String num = n ; int dec_value = 0 ; int base = 1 ; int len = num . length ( ) ; for ( int i = len - 1 ; i >= 0 ; i -- ) { if ( num . charAt ( i ) == '1' ) dec_value += base ; base = base * 2 ; } return dec_value ; } static String decimalToBinary ( int n ) { String binstr = " " ; while ( n > 0 ) { binstr += ( char ) ( n % 2 + 48 ) ; n = n / 2 ; } return binstr ; } static int reversedBinaryDecimal ( int N ) { String decimal_to_binar = decimalToBinary ( N ) ; int binary_to_decimal = binaryToDecimal ( decimal_to_binar ) ; return binary_to_decimal ; } static void printSortedArray ( int arr [ ] , int size ) { Arrays . sort ( arr ) ; for ( int i = 0 ; i < size ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( ) ; } static void modifyArray ( int arr [ ] , int size ) { for ( int i = 0 ; i < size ; i ++ ) { arr [ i ] = reversedBinaryDecimal ( arr [ i ] ) ; } printSortedArray ( arr , size ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 98 , 43 , 66 , 83 } ; int n = arr . length ; modifyArray ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: binstr, dec_value, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isSortedArray ( int [ ] arr , int n ) { int l = 0 , r = ( n - 1 ) ; while ( ( l + 1 ) < r ) { if ( arr [ l ] >= Math . max ( arr [ l + 1 ] , arr [ r - 1 ] ) && arr [ r ] >= Math . max ( arr [ r - 1 ] , arr [ l + 1 ] ) ) { l ++ ; r -- ; } else { return false ; } } return true ; } public static void main ( String args [ ] ) { int [ ] arr = { 4 , 3 , 1 , 2 , 5 } ; int N = arr . length ; if ( isSortedArray ( arr , N ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: l, r
Accumulator variables: l, r
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void maxLenSubset ( int a [ ] , int n ) { Arrays . sort ( a ) ; int index = 0 , maxlen = - 1 ; int i = 0 ; while ( i < n ) { int j = i ; int len = 1 ; while ( j < n - 1 ) { if ( 2 * a [ j ] >= a [ j + 1 ] ) { len ++ ; } else break ; j ++ ; } if ( maxlen < len ) { maxlen = len ; index = i ; } j ++ ; i = j ; } i = index ; while ( maxlen > 0 ) { System . out . print ( a [ i ] + " ▁ " ) ; maxlen -- ; i ++ ; } } public static void main ( String [ ] args ) { int a [ ] = { 3 , 1 , 5 , 11 } ; int n = a . length ; maxLenSubset ( a , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, len, maxlen
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int solve ( int N , int X [ ] , int Y [ ] ) { ArrayList < int [ ] > p = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { p . add ( new int [ ] { X [ i ] , Y [ i ] } ) ; } Collections . sort ( p , ( p1 , p2 ) -> { if ( p1 [ 0 ] != p2 [ 0 ] ) return p1 [ 0 ] - p2 [ 0 ] ; return p1 [ 1 ] - p2 [ 1 ] ; } ) ; TreeSet < Integer > s = new TreeSet < > ( ) ; s . add ( p . get ( 0 ) [ 1 ] ) ; for ( int i = 0 ; i < N ; i ++ ) { Integer it = s . floor ( p . get ( i ) [ 1 ] ) ; if ( it == null ) { s . add ( p . get ( i ) [ 1 ] ) ; } else { s . remove ( it ) ; s . add ( p . get ( i ) [ 1 ] ) ; } } return s . size ( ) ; } public static void main ( String [ ] args ) { int N = 3 ; int X [ ] = { 1 , 2 , 0 } ; int Y [ ] = { 2 , 0 , 1 } ; int maxintersection = solve ( N , X , Y ) ; System . out . println ( maxintersection ) ; } }

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