dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
public class GFG { public static void findIndices ( int arr [ ] , int n ) { int leftMin = 0 , rightMin = 0 ; int leftMax = 0 , rightMax = 0 ; int min = arr [ 0 ] , max = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < min ) { leftMin = rightMin = i ; min = arr [ i ] ; } else if ( arr [ i ] == min ) rightMin = i ; if ( arr [ i ] > max ) { leftMax = rightMax = i ; max = arr [ i ] ; } else if ( arr [ i ] == max ) rightMax = i ; } System . out . println ( " Minimum ▁ left ▁ : ▁ " + leftMin ) ; System . out . println ( " Minimum ▁ right ▁ : ▁ " + rightMin ) ; System . out . println ( " Maximum ▁ left ▁ : ▁ " + leftMax ) ; System . out . println ( " Maximum ▁ right ▁ : ▁ " + rightMax ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 1 , 1 , 2 , 1 , 5 , 6 , 5 } ; int n = arr . length ; findIndices ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static void diagonalsMinMax ( int [ ] [ ] mat ) { int n = mat . length ; if ( n == 0 ) return ; int principalMin = mat [ 0 ] [ 0 ] , principalMax = mat [ 0 ] [ 0 ] ; int secondaryMin = mat [ n - 1 ] [ 0 ] , secondaryMax = mat [ n - 1 ] [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) { if ( i == j ) { if ( mat [ i ] [ j ] < principalMin ) { principalMin = mat [ i ] [ j ] ; } if ( mat [ i ] [ j ] > principalMax ) { principalMax = mat [ i ] [ j ] ; } } if ( ( i + j ) == ( n - 1 ) ) { if ( mat [ i ] [ j ] < secondaryMin ) { secondaryMin = mat [ i ] [ j ] ; } if ( mat [ i ] [ j ] > secondaryMax ) { secondaryMax = mat [ i ] [ j ] ; } } } } System . out . println ( " Principal ▁ Diagonal ▁ Smallest ▁ Element : ▁ " + principalMin ) ; System . out . println ( " Principal ▁ Diagonal ▁ Greatest ▁ Element ▁ : ▁ " + principalMax ) ; System . out . println ( " Secondary ▁ Diagonal ▁ Smallest ▁ Element : ▁ " + secondaryMin ) ; System . out . println ( " Secondary ▁ Diagonal ▁ Greatest ▁ Element : ▁ " + secondaryMax ) ; } static public void main ( String [ ] args ) { int [ ] [ ] matrix = { { 1 , 2 , 3 , 4 , - 10 } , { 5 , 6 , 7 , 8 , 6 } , { 1 , 2 , 11 , 3 , 4 } , { 5 , 6 , 70 , 5 , 8 } , { 4 , 9 , 7 , 1 , - 5 } } ; diagonalsMinMax ( matrix ) ; } }

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 indexedSequentialSearch ( int arr [ ] , int n , int k ) { int elements [ ] = new int [ 20 ] ; int indices [ ] = new int [ 20 ] ; int temp , i ; int j = 0 , ind = 0 , start = 0 , end = 0 , set = 0 ; for ( i = 0 ; i < n ; i += 3 ) { elements [ ind ] = arr [ i ] ; indices [ ind ] = i ; ind ++ ; } if ( k < elements [ 0 ] ) { System . out . println ( " Not ▁ found " ) ; return ; } else { for ( i = 1 ; i <= ind ; i ++ ) if ( k <= elements [ i ] ) { start = indices [ i - 1 ] ; set = 1 ; end = indices [ i ] ; break ; } } if ( set == 0 ) { start = indices [ i - 1 ] ; end = n ; } for ( i = start ; i <= end ; i ++ ) { if ( k == arr [ i ] ) { j = 1 ; break ; } } if ( j == 1 ) System . out . println ( " Found ▁ at ▁ index ▁ " + i ) ; else System . out . println ( " Not ▁ found " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 6 , 7 , 8 , 9 , 10 } ; int n = arr . length ; int k = 8 ; indexedSequentialSearch ( arr , n , k ) ; } }

Index/key variables: i, ind
Accumulator variables: i, ind
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int getCount ( int [ ] v , int n ) { Arrays . sort ( v ) ; int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int tmp = n - 1 - upperBound ( v , n , v [ i ] - 1 ) ; if ( tmp == v [ i ] ) cnt ++ ; } return cnt ; } static int upperBound ( int [ ] array , int length , int value ) { int low = 0 ; int high = length ; while ( low < high ) { final int mid = ( low + high ) / 2 ; if ( value >= array [ mid ] ) { low = mid + 1 ; } else { high = mid ; } } return low ; } public static void main ( String [ ] args ) { int n = 4 ; int [ ] v = { 1 , 2 , 3 , 4 } ; System . out . println ( getCount ( v , n ) ) ; } }

Index/key variables: i, mid
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countSegments ( int a [ ] , int n , int x ) { boolean flag = false ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > x ) { flag = true ; } else { if ( flag ) count += 1 ; flag = false ; } } if ( flag ) count += 1 ; return count ; } public static void main ( String [ ] args ) { int a [ ] = { 8 , 25 , 10 , 19 , 19 , 18 , 20 , 11 , 18 } ; int n = a . length ; int x = 13 ; System . out . println ( countSegments ( a , n , x ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . util . HashMap ; import java . util . Map ; public class GFG { static void findElements ( int arr [ ] , int n , int l , int r ) { Map < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { int a = 0 ; if ( mp . get ( arr [ i ] ) == null ) { a = 1 ; } else { a = mp . get ( arr [ i ] ) + 1 ; } mp . put ( arr [ i ] , a ) ; } for ( int i = 0 ; i < n ; ++ i ) { if ( l <= mp . get ( arr [ i ] ) && ( mp . get ( arr [ i ] ) <= r ) ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 3 , 2 , 2 , 5 } ; int n = arr . length ; int l = 2 , r = 3 ; findElements ( arr , n , l , r ) ; } }

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

Accumulator variables: count, i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int maxs = 1000001 ; static int kthSmallestLargest ( int [ ] arr , int n , int k ) { int max_val = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; int hash [ ] = new int [ max_val + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { hash [ arr [ i ] ] ++ ; } int count = 0 ; for ( int i = 0 ; i <= max_val ; i ++ ) { while ( hash [ i ] > 0 ) { count ++ ; if ( count == k ) { return i ; } hash [ i ] -- ; } } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 11 , 6 , 2 , 9 , 4 , 3 , 16 } ; int n = arr . length , k = 3 ; System . out . println ( " kth ▁ smallest ▁ number ▁ is : ▁ " + kthSmallestLargest ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . Arrays ; class GFG { static int findSum ( int minEle , int maxEle ) { return minEle + maxEle ; } static int findProduct ( int minEle , int maxEle ) { return minEle * maxEle ; } public static void main ( String [ ] args ) { int [ ] arr = { 12 , 1234 , 45 , 67 , 1 } ; int n = arr . length ; Arrays . sort ( arr ) ; int minEle = arr [ 0 ] ; int maxEle = arr [ n - 1 ] ; System . out . println ( " Sum ▁ = ▁ " + findSum ( minEle , maxEle ) ) ; System . out . println ( " Product ▁ = ▁ " + findProduct ( minEle , maxEle ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . Vector ; import com . google . common . math . BigIntegerMath ; import java . math . * ; class GFG { static int bsearch ( Vector < Integer > A , int key_to_search ) { int n = ( int ) A . size ( ) ; int lg = BigIntegerMath . log2 ( BigInteger . valueOf ( n - 1 ) , RoundingMode . UNNECESSARY ) + 1 ; int pos = 0 ; for ( int i = lg - 1 ; i >= 0 ; i -- ) { if ( A . get ( pos ) == key_to_search ) { return pos ; } int new_pos = pos | ( 1 << i ) ; if ( ( new_pos < n ) && ( A . get ( new_pos ) <= key_to_search ) ) { pos = new_pos ; } } return ( ( A . get ( pos ) == key_to_search ) ? pos : - 1 ) ; } static public void main ( String [ ] args ) { Vector < Integer > A = new Vector < Integer > ( ) ; int [ ] arr = { - 2 , 10 , 100 , 250 , 32315 } ; for ( int i = 0 ; i < arr . length ; i ++ ) { A . add ( arr [ i ] ) ; } System . out . println ( bsearch ( A , 10 ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void answerQueries ( int [ ] [ ] a , int n , int [ ] queries , int q ) { Vector < Integer > v = new Vector < > ( ) ; HashMap < Integer , Integer > mpp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { v . add ( a [ i ] [ 0 ] ) ; mpp . put ( a [ i ] [ 0 ] , 1 ) ; v . add ( a [ i ] [ 1 ] ) ; mpp . put ( a [ i ] [ 1 ] , 2 ) ; } Collections . sort ( v ) ; for ( int i = 0 ; i < q ; i ++ ) { int num = queries [ i ] ; int ind = lowerBound ( v , num ) ; if ( ind >= 0 && v . elementAt ( ind ) == num ) System . out . println ( " Yes " ) ; else { if ( ind >= 0 && mpp . get ( v . elementAt ( ind ) ) == 2 ) System . out . println ( " Yes " ) ; System . out . println ( " No " ) ; } } } static int lowerBound ( Vector < Integer > array , int value ) { int low = 0 ; int high = array . size ( ) ; while ( low < high ) { final int mid = ( low + high ) / 2 ; if ( value <= array . elementAt ( mid ) ) { high = mid ; } else { low = mid + 1 ; } } return low ; } public static void main ( String [ ] args ) { int [ ] [ ] a = { { 5 , 6 } , { 1 , 3 } , { 8 , 10 } } ; int n = 3 ; int [ ] queries = { 2 , 3 , 4 , 7 } ; int q = queries . length ; answerQueries ( a , n , queries , q ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static float findmedian ( int a [ ] , int n1 , int b [ ] , int n2 ) { int i = 0 ; int j = 0 ; int k ; int m1 = - 1 , m2 = - 1 ; for ( k = 0 ; k <= ( n1 + n2 ) / 2 ; k ++ ) { if ( i < n1 && j < n2 ) { if ( a [ i ] < b [ j ] ) { m2 = m1 ; m1 = a [ i ] ; i ++ ; } else { m2 = m1 ; m1 = b [ j ] ; j ++ ; } } else if ( i == n1 ) { m2 = m1 ; m1 = b [ j ] ; j ++ ; } else if ( j == n2 ) { m2 = m1 ; m1 = a [ i ] ; i ++ ; } } if ( ( n1 + n2 ) % 2 == 0 ) { return ( m1 + m2 ) * ( float ) 1.0 / 2 ; } return m1 ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 12 , 15 , 26 , 38 } ; int b [ ] = { 2 , 13 , 24 } ; int n1 = a . length ; int n2 = b . length ; System . out . println ( findmedian ( a , n1 , b , n2 ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: k
Class/struct names: GFG
Java program:
class Main { static void printNSE ( int arr [ ] , int n ) { int next , i , j ; for ( i = 0 ; i < n ; i ++ ) { next = - 1 ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] > arr [ j ] ) { next = arr [ j ] ; break ; } } System . out . println ( arr [ i ] + " ▁ - - ▁ " + next ) ; } } public static void main ( String args [ ] ) { int arr [ ] = { 11 , 13 , 21 , 3 } ; int n = arr . length ; printNSE ( arr , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
public class Demo { public static int longestSubarray ( int [ ] input ) { int prev = - 1 ; int current , next ; int prevCount = 0 , currentCount = 1 ; int longest = 1 ; current = input [ 0 ] ; for ( int i = 1 ; i < input . length ; i ++ ) { next = input [ i ] ; if ( next == current ) { currentCount ++ ; } else if ( next == prev ) { prevCount += currentCount ; prev = current ; current = next ; currentCount = 1 ; } else { longest = Math . max ( longest , currentCount + prevCount ) ; prev = current ; prevCount = currentCount ; current = next ; currentCount = 1 ; } } return Math . max ( longest , currentCount + prevCount ) ; } public static void main ( String [ ] args ) { int [ ] input = { 5 , 5 , 6 , 7 , 6 } ; System . out . println ( longestSubarray ( input ) ) ; } }

Index/key variables: i
Accumulator variables: currentCount, i, prevCount
Iterator variables: i
Class/struct names: Demo
Java program:
import java . util . * ; class solution { static class Node { int data ; Node left , right ; } ; static class INT { int data ; } ; static Node reverseTreePathUtil ( Node root , int data , Map < Integer , Integer > temp , int level , INT nextpos ) { if ( root == null ) return null ; if ( data == root . data ) { temp . put ( level , root . data ) ; root . data = temp . get ( nextpos . data ) ; nextpos . data ++ ; return root ; } temp . put ( level , root . data ) ; Node left , right = null ; left = reverseTreePathUtil ( root . left , data , temp , level + 1 , nextpos ) ; if ( left == null ) right = reverseTreePathUtil ( root . right , data , temp , level + 1 , nextpos ) ; if ( left != null right != null ) { root . data = temp . get ( nextpos . data ) ; nextpos . data ++ ; return ( left != null ? left : right ) ; } return null ; } static void reverseTreePath ( Node root , int data ) { Map < Integer , Integer > temp = new HashMap < Integer , Integer > ( ) ; INT nextpos = new INT ( ) ; nextpos . data = 0 ; reverseTreePathUtil ( root , data , temp , 0 , nextpos ) ; } static void inorder ( Node root ) { if ( root != null ) { inorder ( root . left ) ; System . out . print ( root . data + " ▁ " ) ; inorder ( root . right ) ; } } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } public static void main ( String args [ ] ) { Node root = newNode ( 7 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 2 ) ; root . right . right = newNode ( 1 ) ; int data = 4 ; reverseTreePath ( root , data ) ; inorder ( root ) ; } }

Accumulator variables: data
Class/struct names: INT, Node, solution
Java program:
class GFG { static int binarySearch ( int [ ] searchSpace , int s , int e , int num ) { int ans = 0 ; while ( s <= e ) { int mid = ( s + e ) / 2 ; if ( searchSpace [ mid ] >= num ) { ans = mid ; e = mid - 1 ; } else s = mid + 1 ; } return ans ; } static int longestSubArr ( int [ ] arr , int n ) { int [ ] searchSpace = new int [ n ] ; int [ ] index = new int [ n ] ; int j = 0 ; int ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( j == 0 searchSpace [ j - 1 ] < arr [ i ] ) { searchSpace [ j ] = arr [ i ] ; index [ j ] = i ; j ++ ; } int idx = binarySearch ( searchSpace , 0 , j - 1 , arr [ i ] ) ; ans = Math . max ( ans , i - index [ idx ] + 1 ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { - 5 , - 1 , 7 , 5 , 1 , - 2 } ; int n = arr . length ; System . out . println ( longestSubArr ( arr , n ) ) ; } }

Index/key variables: i, idx, j, mid, n
Accumulator variables: j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; public class SumOfPairs { public void pairedElements ( int arr [ ] , int sum ) { int low = 0 ; int high = arr . length - 1 ; while ( low < high ) { if ( arr [ low ] + arr [ high ] == sum ) { System . out . println ( " The ▁ pair ▁ is ▁ : ▁ ( " + arr [ low ] + " , ▁ " + arr [ high ] + " ) " ) ; } if ( arr [ low ] + arr [ high ] > sum ) { high -- ; } else { low ++ ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , - 2 , 6 , 8 , 9 , 11 } ; Arrays . sort ( arr ) ; SumOfPairs sp = new SumOfPairs ( ) ; sp . pairedElements ( arr , 6 ) ; } }

Index/key variables: high, low
Accumulator variables: high, low
Class/struct names: SumOfPairs
Java program:
class GFG { static boolean isSuffix ( String s1 , String s2 ) { int n1 = s1 . length ( ) , n2 = s2 . length ( ) ; if ( n1 > n2 ) return false ; for ( int i = 0 ; i < n1 ; i ++ ) if ( s1 . charAt ( n1 - i - 1 ) != s2 . charAt ( n2 - i - 1 ) ) return false ; return true ; } public static void main ( String [ ] args ) { String s1 = " geeks " , s2 = " geeksforgeeks " ; boolean result = isSuffix ( s1 , s2 ) ; if ( result ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static boolean checkIfAllTogether ( String s , char c ) { boolean oneSeen = false ; int i = 0 , n = s . length ( ) ; while ( i < n ) { if ( s . charAt ( i ) == c ) { if ( oneSeen == true ) return false ; while ( i < n && s . charAt ( i ) == c ) i ++ ; oneSeen = true ; } else i ++ ; } return true ; } public static void main ( String [ ] args ) { String s = "110029" ; if ( checkIfAllTogether ( s , '1' ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: i
Boolean variables: oneSeen
Class/struct names: GFG
Java program:
class GFG { static boolean search ( int arr [ ] , int n , int x ) { int front = 0 , back = n - 1 ; while ( front <= back ) { if ( arr [ front ] == x arr [ back ] == x ) return true ; front ++ ; back -- ; } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 20 , 80 , 30 , 60 , 50 , 110 , 100 , 130 , 170 } ; int x = 130 ; int n = arr . length ; if ( search ( arr , n , x ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Index/key variables: back, front
Accumulator variables: back, front
Class/struct names: GFG
Java program:
import java . util . * ; class Even_odd { public static int findValue ( int X , int Y , int P ) { if ( P % 2 == 0 ) return ( Math . max ( X , Y ) / Math . min ( X , Y ) ) ; else return ( Math . max ( 2 * X , Y ) / Math . min ( 2 * X , Y ) ) ; } public static void main ( String [ ] args ) { int X = 1 , Y = 2 , P = 1 ; System . out . println ( findValue ( X , Y , P ) ) ; X = 3 ; Y = 7 ; P = 2 ; System . out . print ( findValue ( X , Y , P ) ) ; } }

Class/struct names: Even_odd
Java program:
import java . util . * ; import java . io . * ; class GFG { static int sum ( int arr [ ] , int from , int to ) { int total = 0 ; for ( int i = from ; i <= to ; i ++ ) total += arr [ i ] ; return total ; } static int findMax ( int arr [ ] , int n , int k ) { int dp [ ] [ ] = new int [ k + 1 ] [ n + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) dp [ 1 ] [ i ] = sum ( arr , 0 , i - 1 ) ; for ( int i = 1 ; i <= k ; i ++ ) dp [ i ] [ 1 ] = arr [ 0 ] ; for ( int j = 2 ; j <= n ; j ++ ) { int best = Integer . MAX_VALUE ; for ( int p = 1 ; p <= j ; p ++ ) best = Math . min ( best , Math . max ( dp [ i - 1 ] [ p ] , sum ( arr , p , j - 1 ) ) ) ; dp [ i ] [ j ] = best ; } } return dp [ k ] [ n ] ; } public static void main ( String args [ ] ) { int arr [ ] = { 10 , 20 , 60 , 50 , 30 , 40 } ; int n = arr . length ; int k = 3 ; System . out . println ( findMax ( arr , n , k ) ) ; } }

Index/key variables: i, j, k, n, p
Accumulator variables: i, j, p, total
Iterator variables: i, j, p
Class/struct names: GFG
Java program:
class GFG { static int countCrossLine ( int arr [ ] , int n ) { int count_crossline = 0 ; int i , key , j ; for ( i = 1 ; i < n ; i ++ ) { key = arr [ i ] ; j = i - 1 ; while ( j >= 0 && arr [ j ] > key ) { arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; count_crossline ++ ; } arr [ j + 1 ] = key ; } return count_crossline ; } public static void main ( String args [ ] ) { int arr [ ] = new int [ ] { 4 , 3 , 1 , 2 } ; int n = arr . length ; System . out . print ( countCrossLine ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: count_crossline, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int findMaxRec ( int A [ ] , int n ) { if ( n == 1 ) return A [ 0 ] ; return Math . max ( A [ n - 1 ] , findMaxRec ( A , n - 1 ) ) ; } public static void main ( String args [ ] ) { int A [ ] = { 1 , 4 , 45 , 6 , - 50 , 10 , 2 } ; int n = A . length ; System . out . println ( findMaxRec ( A , n ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . Arrays ; import java . util . List ; class GFG { static String remVowel ( String str ) { return str . replaceAll ( " [ aeiouAEIOU ] " , " " ) ; } public static void main ( String [ ] args ) { String str = " GeeeksforGeeks ▁ - ▁ A ▁ Computer ▁ Science ▁ Portal ▁ for ▁ Geeks " ; System . out . println ( remVowel ( str ) ) ; } }

Index/key variables: aeiouAEIOU
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findAmountPlayers ( int [ ] arr , int N ) { Arrays . sort ( arr ) ; reverse ( arr , N ) ; int amountA = 0 ; int amountB = 0 ; if ( N == 1 ) { amountA += arr [ 0 ] ; System . out . println ( " ( A ▁ : ▁ " + amountA + " ) , ▁ " + " ( B ▁ : ▁ " + amountB + " ) " ) ; return ; } amountA = arr [ 0 ] ; amountB = arr [ 1 ] ; for ( int i = 2 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { amountB += arr [ i ] ; } else { amountA += arr [ i ] ; } } System . out . println ( " ( A ▁ : ▁ " + amountA + " ) " ) ; System . out . println ( " ( B ▁ : ▁ " + amountB + " ) " ) ; } static void reverse ( int a [ ] , int n ) { int [ ] b = new int [ n ] ; int j = n ; for ( int i = 0 ; i < n ; i ++ ) { b [ j - 1 ] = a [ i ] ; j = j - 1 ; } } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 1 } ; int N = arr . length ; findAmountPlayers ( arr , N ) ; } }

Index/key variables: i, n
Accumulator variables: amountA, amountB, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . lang . * ; import java . util . * ; class pair { int first , second ; pair ( int first , int second ) { this . first = first ; this . second = second ; } } class GFG { static int minSwapsAsc ( int [ ] arr , int n ) { pair [ ] arrPos = new pair [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arrPos [ i ] = new pair ( arr [ i ] , i ) ; } Arrays . sort ( arrPos , ( a , b ) -> a . first - b . first ) ; boolean [ ] vis = new boolean [ n ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( vis [ i ] arrPos [ i ] . second == i ) continue ; int cycle_size = 0 ; int j = i ; while ( ! vis [ j ] ) { vis [ j ] = true ; j = arrPos [ j ] . second ; cycle_size ++ ; } if ( cycle_size > 0 ) { ans += ( cycle_size - 1 ) ; } } return ans ; } static int minSwapsDes ( int [ ] arr , int n ) { pair [ ] arrPos = new pair [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arrPos [ i ] = new pair ( arr [ i ] , i ) ; } Arrays . sort ( arrPos , ( a , b ) -> b . first - a . first ) ; boolean [ ] vis = new boolean [ n ] ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( vis [ i ] arrPos [ i ] . second == i ) continue ; int cycle_size = 0 ; int j = i ; while ( ! vis [ j ] ) { vis [ j ] = true ; j = arrPos [ j ] . second ; cycle_size ++ ; } if ( cycle_size > 0 ) { ans += ( cycle_size - 1 ) ; } } return ans ; } static int minimumSwaps ( int [ ] arr ) { int S1 = minSwapsAsc ( arr , arr . length ) ; int S2 = minSwapsDes ( arr , arr . length ) ; return Math . min ( S1 , S2 ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 4 , 2 , 5 , 1 } ; System . out . println ( minimumSwaps ( arr ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: ans, cycle_size, i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void sortArray ( int [ ] arr , int N ) { int i = 0 , j = N - 1 , mid = 0 ; while ( mid <= j ) { if ( arr [ mid ] == 0 ) { int temp = arr [ i ] ; arr [ i ] = arr [ mid ] ; arr [ mid ] = temp ; i ++ ; mid ++ ; } else if ( arr [ mid ] == 3 ) { int temp = arr [ mid ] ; arr [ mid ] = arr [ j ] ; arr [ j ] = temp ; j -- ; } else if ( arr [ mid ] == 1 arr [ mid ] == 2 ) { mid ++ ; } } while ( i <= j ) { if ( arr [ i ] == 2 ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; j -- ; } else { i ++ ; } } for ( int k = 0 ; k < N ; k ++ ) { System . out . print ( arr [ k ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 1 , 0 , 2 , 3 , 1 , 0 } ; int N = arr . length ; sortArray ( arr , N ) ; } }

Index/key variables: i, j, k, mid
Accumulator variables: i, j, k, mid
Iterator variables: k
Class/struct names: GFG