dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; class GFG { static int findLastIndex ( String str , Character x ) { for ( int i = str . length ( ) - 1 ; i >= 0 ; i -- ) if ( str . charAt ( i ) == x ) return i ; return - 1 ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; Character x = ' e ' ; int index = findLastIndex ( str , x ) ; if ( index == - 1 ) System . out . println ( " Character ▁ not ▁ found " ) ; else System . out . println ( " Last ▁ index ▁ is ▁ " + index ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countMaxSetBits ( int left , int right ) { while ( ( left | ( left + 1 ) ) <= right ) left |= left + 1 ; return left ; } public static void main ( String [ ] args ) { int l = 1 ; int r = 5 ; System . out . println ( countMaxSetBits ( l , r ) ) ; l = 1 ; r = 10 ; System . out . println ( countMaxSetBits ( l , r ) ) ; } }

Accumulator variables: left
Class/struct names: GFG
Java program:
class GFG { static class Node { int key ; Node left , right ; } ; static Node newNode ( int item ) { Node temp = new Node ( ) ; temp . key = item ; temp . left = temp . right = null ; return temp ; } static Node insert ( Node node , int key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insert ( node . left , key ) ; else if ( key > node . key ) node . right = insert ( node . right , key ) ; return node ; } static int findFloor ( Node root , int key ) { Node curr = root , ans = null ; while ( curr != null ) { if ( curr . key <= key ) { ans = curr ; curr = curr . right ; } else curr = curr . left ; } if ( ans != null ) return ans . key ; return - 1 ; } public static void main ( String [ ] args ) { int N = 25 ; Node root = new Node ( ) ; insert ( root , 19 ) ; insert ( root , 2 ) ; insert ( root , 1 ) ; insert ( root , 3 ) ; insert ( root , 12 ) ; insert ( root , 9 ) ; insert ( root , 21 ) ; insert ( root , 19 ) ; insert ( root , 25 ) ; System . out . printf ( " % d " , findFloor ( root , N ) ) ; } }

Class/struct names: GFG, Node
Java program:
import java . io . * ; public class GFG { static int findS ( int s ) { int l = 1 , r = ( s / 2 ) + 1 ; while ( l <= r ) { int mid = ( l + r ) / 2 ; int sum = mid * ( mid + 1 ) / 2 ; if ( sum == s ) return mid ; else if ( sum > s ) r = mid - 1 ; else l = mid + 1 ; } return - 1 ; } static public void main ( String [ ] args ) { int s = 15 ; int n = findS ( s ) ; if ( n == - 1 ) System . out . println ( " - 1" ) ; else System . out . println ( n ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int compareStrings ( String str1 , String str2 ) { int i = 0 ; while ( i < str1 . length ( ) - 1 && str1 . charAt ( i ) == str2 . charAt ( i ) ) i ++ ; if ( str1 . charAt ( i ) > str2 . charAt ( i ) ) return - 1 ; if ( str1 . charAt ( i ) < str2 . charAt ( i ) ) return 1 ; else return 0 ; } static int searchStr ( String [ ] arr , String str , int first , int last ) { if ( first > last ) return - 1 ; int mid = ( last + first ) / 2 ; if ( arr [ mid ] . isEmpty ( ) ) { int left = mid - 1 ; int right = mid + 1 ; while ( true ) { if ( left < right && right > last ) return - 1 ; if ( right <= last && ! arr [ right ] . isEmpty ( ) ) { mid = right ; break ; } if ( left >= right && ! arr [ left ] . isEmpty ( ) ) { mid = left ; break ; } right ++ ; left -- ; } } if ( compareStrings ( str , arr [ mid ] ) == 0 ) return mid ; if ( compareStrings ( str , arr [ mid ] ) < 0 ) return searchStr ( arr , str , mid + 1 , last ) ; return searchStr ( arr , str , first , mid - 1 ) ; } public static void main ( String [ ] args ) { String [ ] arr = { " for " , " " , " " , " " , " geeks " , " ide " , " " , " practice " , " " , " " , " quiz " , " " , " " } ; String str = " quiz " ; int n = arr . length ; System . out . println ( searchStr ( arr , str , 0 , n - 1 ) ) ; } }

Index/key variables: left, mid, right
Accumulator variables: i, left, right
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int countReduction ( int num ) { int ans = 0 ; while ( num >= 10 ) { int temp = num ; num = 1 ; while ( temp > 0 ) { int digit = temp % 10 ; temp = temp / 10 ; num *= digit ; } ans ++ ; } return ans ; } int x1 = countReduction ( x ) ; int y1 = countReduction ( y ) ; if ( x1 < y1 ) return - 1 ; return 1 ; } } ) ; static void sortArray ( Integer a [ ] , int n ) { Arrays . sort ( a , new Comparator < Integer > ( ) { public int compare ( Integer x , Integer y ) { for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( a [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { Integer arr [ ] = { 39 , 999 , 4 , 9876 } ; int N = arr . length ; sortArray ( arr , N ) ; } }

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

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static void maximumMex ( int arr [ ] , int N ) { int ans [ ] = new int [ 2 * N ] ; Arrays . sort ( ans ) ; int j = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == 0 arr [ i ] != arr [ i - 1 ] ) { j += 1 ; ans [ j ] = arr [ i ] ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( i > 0 && arr [ i ] == arr [ i - 1 ] ) { j += 1 ; ans [ j ] = arr [ i ] ; } } for ( int i = 0 ; i < N ; i ++ ) System . out . print ( ans [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 0 , 0 } ; int N = arr . length ; maximumMex ( arr , N ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static ArrayList < Integer > bubble_sort ( ArrayList < Integer > ar ) { if ( ar . size ( ) <= 1 ) return ar ; if ( ar . size ( ) == 2 ) { if ( ar . get ( 0 ) < ar . get ( 1 ) ) return ar ; else return new ArrayList < Integer > ( Arrays . asList ( ar . get ( 1 ) , ar . get ( 0 ) ) ) ; } int a = ar . get ( 0 ) ; int b = ar . get ( 1 ) ; ArrayList < Integer > bs = new ArrayList < > ( ) ; for ( int i = 2 ; i < ar . size ( ) ; i ++ ) bs . add ( ar . get ( i ) ) ; ArrayList < Integer > res = new ArrayList < > ( ) ; if ( a < b ) { ArrayList < Integer > temp1 = new ArrayList < > ( ) ; temp1 . add ( b ) ; for ( int i = 0 ; i < bs . size ( ) ; i ++ ) temp1 . add ( bs . get ( i ) ) ; ArrayList < Integer > v = bubble_sort ( temp1 ) ; v . add ( 0 , a ) ; res = v ; } else { ArrayList < Integer > temp1 = new ArrayList < > ( ) ; temp1 . add ( a ) ; for ( int i = 0 ; i < bs . size ( ) ; i ++ ) temp1 . add ( bs . get ( i ) ) ; ArrayList < Integer > v = bubble_sort ( temp1 ) ; v . add ( 0 , b ) ; res = v ; } ArrayList < Integer > pass = new ArrayList < > ( ) ; for ( int i = 0 ; i < res . size ( ) - 1 ; i ++ ) pass . add ( res . get ( i ) ) ; ArrayList < Integer > ans = bubble_sort ( pass ) ; ans . add ( res . get ( res . size ( ) - 1 ) ) ; return ans ; } public static void main ( String [ ] args ) { ArrayList < Integer > arr = new ArrayList < Integer > ( Arrays . asList ( 1 , 3 , 4 , 5 , 6 , 2 ) ) ; ArrayList < Integer > res = bubble_sort ( arr ) ; for ( int i = 0 ; i < res . size ( ) ; i ++ ) System . out . print ( res . get ( i ) + " ▁ " ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printMatrix ( ArrayList < ArrayList < Integer > > a ) { for ( int i = 0 ; i < a . size ( ) ; i ++ ) { for ( int j = 0 ; j < a . get ( i ) . size ( ) ; j ++ ) { System . out . print ( a . get ( i ) . get ( j ) + " ▁ " ) ; } System . out . println ( ) ; } } static void sortBoundaryWise ( ArrayList < ArrayList < Integer > > a ) { int i , k = 0 , l = 0 ; int m = a . size ( ) , n = a . get ( 0 ) . size ( ) ; int n_i , n_k = 0 , n_l = 0 , n_m = m , n_n = n ; while ( k < m && l < n ) { ArrayList < Integer > boundary = new ArrayList < Integer > ( ) ; for ( i = l ; i < n ; ++ i ) { boundary . add ( a . get ( k ) . get ( i ) ) ; } k ++ ; for ( i = k ; i < m ; ++ i ) { boundary . add ( a . get ( i ) . get ( n - 1 ) ) ; } n -- ; if ( k < m ) { for ( i = n - 1 ; i >= l ; -- i ) { boundary . add ( a . get ( m - 1 ) . get ( i ) ) ; } m -- ; } if ( l < n ) { for ( i = m - 1 ; i >= k ; -- i ) { boundary . add ( a . get ( i ) . get ( l ) ) ; } l ++ ; } Collections . sort ( boundary ) ; int ind = 0 ; for ( i = n_l ; i < n_n ; ++ i ) { a . get ( n_k ) . set ( i , boundary . get ( ind ) ) ; ind ++ ; } n_k += 1 ; for ( i = n_k ; i < n_m ; ++ i ) { a . get ( i ) . set ( n_n - 1 , boundary . get ( ind ) ) ; ind ++ ; } n_n -- ; if ( n_k < n_m ) { for ( i = n_n - 1 ; i >= n_l ; -- i ) { a . get ( n_m - 1 ) . set ( i , boundary . get ( ind ) ) ; ind ++ ; } n_m -- ; } if ( n_l < n_n ) { for ( i = n_m - 1 ; i >= n_k ; -- i ) { a . get ( i ) . set ( n_l , boundary . get ( ind ) ) ; ind ++ ; } n_l ++ ; } } printMatrix ( a ) ; } public static void main ( String args [ ] ) { ArrayList < ArrayList < Integer > > matrix = new ArrayList < ArrayList < Integer > > ( ) ; ArrayList < Integer > list1 = new ArrayList < Integer > ( Arrays . asList ( 9 , 7 , 4 , 5 ) ) ; ArrayList < Integer > list2 = new ArrayList < Integer > ( Arrays . asList ( 1 , 6 , 2 , - 6 ) ) ; ArrayList < Integer > list3 = new ArrayList < Integer > ( Arrays . asList ( 12 , 20 , 2 , 0 ) ) ; ArrayList < Integer > list4 = new ArrayList < Integer > ( Arrays . asList ( - 5 , - 6 , 7 , - 2 ) ) ; matrix . add ( list1 ) ; matrix . add ( list2 ) ; matrix . add ( list3 ) ; matrix . add ( list4 ) ; sortBoundaryWise ( matrix ) ; } }

Accumulator variables: i, ind, j, k, l, m, n, n_k, n_l, n_m, n_n
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minimum_sum ( int [ ] A , int N ) { Arrays . sort ( A ) ; int sum = 2147483647 ; for ( int i = 0 ; i <= N - 3 ; i ++ ) { sum = Math . min ( sum , Math . abs ( A [ i ] - A [ i + 1 ] ) + Math . abs ( A [ i + 1 ] - A [ i + 2 ] ) ) ; } return sum ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 1 , 2 , 3 } ; int N = A . length ; System . out . print ( minimum_sum ( A , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . Arrays ; class GFG { static void sameChar ( String S , int N ) { char temp [ ] = S . toCharArray ( ) ; Arrays . sort ( temp ) ; String s = new String ( temp ) ; int mid = s . charAt ( N / 2 ) ; int total_operations = 0 ; for ( int i = 0 ; i < N ; i ++ ) { total_operations += Math . abs ( ( ( s . charAt ( i ) - 0 ) - mid ) ) ; } System . out . print ( total_operations ) ; } public static void main ( String [ ] args ) { String S = " geeks " ; int N = S . length ( ) ; sameChar ( S , N ) ; } }

Accumulator variables: i, total_operations
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . math . * ; import java . util . * ; public class GFG { static int maxScore ( int i , int A [ ] , int K , int N , int dp [ ] ) { if ( i >= N - 1 ) return A [ N - 1 ] ; if ( dp [ i ] != - 1 ) return dp [ i ] ; int score = Integer . MIN_VALUE ; for ( int j = 1 ; j <= K ; j ++ ) { score = Math . max ( score , maxScore ( i + j , A , K , N , dp ) ) ; } return dp [ i ] = score + A [ i ] ; } static void getScore ( int A [ ] , int N , int K ) { int dp [ ] = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) dp [ i ] = - 1 ; System . out . println ( maxScore ( 0 , A , K , N , dp ) ) ; } public static void main ( String args [ ] ) { int A [ ] = { 100 , - 30 , - 50 , - 15 , - 20 , - 30 } ; int K = 3 ; int N = A . length ; getScore ( A , N , K ) ; } }

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

Index/key variables: a, b
Accumulator variables: a, b, c, count
Iterator variables: a, b, c
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . Arrays ; class GFG { public static boolean findAns ( int [ ] A , int N , int X ) { if ( check ( A , X ) ) { return true ; } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int gcd = gcd ( A [ i ] , A [ j ] ) ; if ( gcd != 1 ) { if ( gcd <= X ) { return true ; } } } } return false ; } public static boolean check ( int [ ] A , int X ) { for ( int i = 0 ; i < A . length ; i ++ ) { if ( A [ i ] > X ) { return false ; } } return true ; } public static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } public static void main ( String [ ] args ) { int X = 4 ; int [ ] A = { 2 , 1 , 5 , 3 , 6 } ; int N = 5 ; System . out . println ( findAns ( A , N , X ) ) ; } }

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 { static String check ( int [ ] a , int [ ] b , int Na , int Nb , int k , int m ) { if ( Na < k Nb < m ) return " No " ; Arrays . sort ( a ) ; Arrays . sort ( b ) ; if ( a [ k - 1 ] < b [ Nb - m ] ) { return " Yes " ; } return " No " ; } public static void main ( String [ ] args ) { int [ ] arr1 = { 1 , 2 , 3 } ; int [ ] arr2 = { 3 , 4 , 5 } ; int N = arr1 . length ; int M = arr2 . length ; int X = 2 , Y = 1 ; System . out . println ( check ( arr1 , arr2 , N , M , X , Y ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isIncreasing ( int [ ] arr ) { for ( int i = 0 ; i < arr . length - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) return false ; } return true ; } static int [ ] sortArr ( int [ ] arr ) { int prev = - 1 ; for ( int i = 0 ; i < arr . length ; i ++ ) { int optEle = arr [ i ] ; String strEle = String . valueOf ( arr [ i ] ) ; for ( int idx = 0 ; idx < strEle . length ( ) ; idx ++ ) { String strEle2 = strEle . substring ( idx ) + strEle . substring ( 0 , idx ) ; int temp = Integer . valueOf ( strEle2 ) ; if ( temp >= prev && temp < optEle ) optEle = temp ; } arr [ i ] = optEle ; prev = arr [ i ] ; } if ( isIncreasing ( arr ) ) return arr ; else { return new int [ ] { - 1 } ; } } public static void main ( String [ ] args ) { int [ ] arr = { 511 , 321 , 323 , 432 , 433 } ; int [ ] res = sortArr ( arr ) ; for ( int i = 0 ; i < res . length ; i ++ ) System . out . print ( res [ i ] + " ▁ " ) ; } }

Index/key variables: i
Accumulator variables: i, idx
Iterator variables: i, idx
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void maxSum ( int arr [ ] , int brr [ ] , int N , int K ) { Vector < Integer > crr = new Vector < Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { crr . add ( arr [ i ] ) ; } for ( int i = 0 ; i < K ; i ++ ) { crr . add ( brr [ i ] ) ; } Collections . sort ( crr ) ; Collections . reverse ( crr ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( crr . get ( i ) > 0 ) { sum += crr . get ( i ) ; } else { break ; } } System . out . println ( sum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 2 , - 1 , 4 , 5 } ; int N = arr . length ; int brr [ ] = { 1 , 2 , 3 , 2 } ; int K = brr . length ; maxSum ( arr , brr , N , K ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void countPairs ( int [ ] A , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { int xo = ( A [ i ] ^ A [ j ] ) ; int mx = Math . max ( A [ i ] , A [ j ] ) ; if ( xo > mx ) { count ++ ; } } } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 4 , 3 } ; int N = arr . length ; countPairs ( arr , N ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class Pair { int first , second ; Pair ( int first , int second ) { this . first = first ; this . second = second ; } } class GFG { static void findTheOrder ( int arr [ ] , String s , int N ) { List < Integer > ans = new ArrayList < Integer > ( ) ; List < Pair > A = new ArrayList < Pair > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Pair p = new Pair ( arr [ i ] , i + 1 ) ; A . add ( p ) ; } Collections . sort ( A , ( p1 , p2 ) -> p1 . first - p2 . first ) ; PriorityQueue < Pair > q = new PriorityQueue < Pair > ( N , ( p1 , p2 ) -> p2 . first - p1 . first ) ; int index = 0 ; for ( int i = 0 ; i < 2 * N ; i ++ ) { if ( s . charAt ( i ) == '0' ) { ans . add ( A . get ( index ) . second ) ; q . add ( A . get ( index ) ) ; index ++ ; } else { ans . add ( q . peek ( ) . second ) ; q . poll ( ) ; } } for ( int i : ans ) { System . out . print ( i + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 3 ; int arr [ ] = { 2 , 1 , 3 } ; String s = "001011" ; findTheOrder ( arr , s , N ) ; } }

Index/key variables: i
Accumulator variables: i, index
Iterator variables: i
Class/struct names: GFG, Pair
Java program:
import java . util . * ; class GFG { static void evenOddDiff ( int a [ ] , int n , int k ) { int j = - 1 ; Vector < Integer > even = new Vector < > ( ) ; Vector < Integer > odd = new Vector < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % 2 == 0 ) { even . add ( a [ i ] ) ; } else odd . add ( a [ i ] ) ; } j ++ ; Collections . sort ( even ) ; Collections . reverse ( even ) ; Collections . sort ( odd ) ; Collections . reverse ( odd ) ; int evenSum = 0 , oddSum = 0 ; for ( int i = 0 ; i < k ; i ++ ) { evenSum += even . get ( i ) ; } for ( int i = 0 ; i < k ; i ++ ) { oddSum += odd . get ( i ) ; } System . out . print ( Math . abs ( evenSum - oddSum ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 8 , 3 , 4 , 5 } ; int N = arr . length ; int K = 2 ; evenOddDiff ( arr , N , K ) ; } }

Index/key variables: i
Accumulator variables: evenSum, i, j, oddSum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printArr ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } static void rearrangeArr ( int arr [ ] , int N ) { int totalSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { totalSum += arr [ i ] ; } if ( totalSum == 0 ) { System . out . print ( " - 1" + "NEW_LINE"); } else if ( totalSum > 0 ) { Arrays . sort ( arr ) ; arr = reverse ( arr ) ; printArr ( arr , N ) ; } else { Arrays . sort ( arr ) ; printArr ( arr , N ) ; } } static int [ ] reverse ( int a [ ] ) { int i , n = a . length , t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , - 1 , - 2 , 3 } ; int N = arr . length ; rearrangeArr ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, totalSum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MOD = 1000000007 ; static int solve ( Vector < Integer > values , Vector < Integer > salary ) { int ret = 1 ; int amt = 0 ; Collections . sort ( values ) ; Collections . sort ( salary ) ; while ( salary . size ( ) > 0 ) { while ( values . size ( ) > 0 && values . get ( values . size ( ) - 1 ) >= salary . get ( salary . size ( ) - 1 ) ) { amt ++ ; values . remove ( values . size ( ) - 1 ) ; } if ( amt == 0 ) return 0 ; ret *= amt -- ; ret %= MOD ; salary . remove ( salary . size ( ) - 1 ) ; } return ret ; } public static void main ( String [ ] args ) { Vector < Integer > values = new Vector < Integer > ( ) ; values . add ( 1 ) ; values . add ( 2 ) ; Vector < Integer > salary = new Vector < Integer > ( ) ; salary . add ( 2 ) ; System . out . print ( solve ( values , salary ) ) ; } }

Accumulator variables: amt, ret
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countPairs ( int arr [ ] , int n ) { int ans = 0 ; Arrays . sort ( arr ) ; int left = 0 , right = 1 ; while ( right < n ) { if ( arr [ left ] == arr [ right ] ) ans += right - left ; else left = right ; right ++ ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 3 , 2 , 3 } ; int N = arr . length ; System . out . print ( countPairs ( arr , N ) ) ; } }

Index/key variables: left, right
Accumulator variables: ans, right
Class/struct names: GFG
Java program:
import java . util . * ; class Pair implements Comparable < Pair > { int first , second ; Pair ( int x , int y ) { first = x ; second = y ; } public int compareTo ( Pair p ) { return p . first - first ; } } class GFG { static int maximiseScore ( int A [ ] , int B [ ] , int K , int N ) { ArrayList < Pair > pairs = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { pairs . add ( new Pair ( A [ i ] , B [ i ] ) ) ; } Collections . sort ( pairs ) ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( pairs . get ( i ) . second == 0 ) { sum += pairs . get ( i ) . first ; } else if ( pairs . get ( i ) . second == 1 ) { if ( K > 0 ) { sum += pairs . get ( i ) . first ; K -- ; } else { sum -= pairs . get ( i ) . first ; } } } return sum ; } public static void main ( String [ ] args ) { int A [ ] = { 5 , 4 , 6 , 2 , 8 } ; int B [ ] = { 1 , 0 , 1 , 1 , 0 } ; int K = 2 ; int N = A . length ; System . out . print ( maximiseScore ( A , B , K , N ) ) ; } }

Index/key variables: i
Accumulator variables: K, i, sum
Iterator variables: i
Class/struct names: GFG, Pair
Java program:
import java . util . * ; class GFG { public static int sortString ( String S ) { Vector < Integer > sorted = new Vector < Integer > ( ) ; Vector < Integer > original = new Vector < Integer > ( ) ; boolean insert = false ; if ( S . length ( ) == 1 ) { System . out . println ( 0 ) ; } int curr = 1 ; for ( int i = 0 ; i < ( S . length ( ) - 1 ) ; i ++ ) { if ( S . charAt ( i ) == S . charAt ( i + 1 ) ) { curr += 1 ; insert = false ; } else { sorted . add ( curr ) ; original . add ( curr ) ; curr = 1 ; insert = true ; } } if ( ( S . charAt ( S . length ( ) - 1 ) != S . charAt ( S . length ( ) - 2 ) ) insert == false ) { sorted . add ( curr ) ; original . add ( curr ) ; } Collections . sort ( sorted ) ; int t_cost = 0 ; for ( int i = 0 ; i < sorted . size ( ) ; i ++ ) { t_cost += Math . abs ( sorted . get ( i ) - original . get ( i ) ) ; } return ( t_cost / 2 ) ; } public static void main ( String [ ] args ) { String S = " aabbcccdeffffggghhhhhii " ; System . out . print ( sortString ( S ) ) ; } }

Accumulator variables: curr, i, t_cost
Iterator variables: i
Boolean variables: insert
Class/struct names: GFG