dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . util . * ; class GFG { static int maxLen ( int A [ ] , int N ) { List < List < Integer > > v = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] == 1 ) { int s = i , len ; while ( i < N && A [ i ] == 1 ) { i ++ ; } len = i - s ; v . add ( Arrays . asList ( len , s , i - 1 ) ) ; } } if ( v . size ( ) == 0 ) { return - 1 ; } int ans = 0 ; for ( int i = 0 ; i < v . size ( ) - 1 ; i ++ ) { ans = Math . max ( ans , v . get ( i ) . get ( 0 ) ) ; if ( v . get ( i + 1 ) . get ( 1 ) - v . get ( i ) . get ( 2 ) - 1 == 2 ) { ans = Math . max ( ans , v . get ( i ) . get ( 0 ) + v . get ( i + 1 ) . get ( 0 ) ) ; } if ( v . get ( i + 1 ) . get ( 1 ) - v . get ( i ) . get ( 2 ) - 1 == 1 ) { ans = Math . max ( ans , v . get ( i ) . get ( 0 ) + v . get ( i + 1 ) . get ( 0 ) - 1 ) ; } } ans = Math . max ( v . get ( v . size ( ) - 1 ) . get ( 0 ) , ans ) ; return ans ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 0 , 1 , 0 , 0 , 1 } ; int N = arr . length ; System . out . println ( maxLen ( 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 t , n , m , a ; static Stack < Integer > s ; static ArrayList < Integer > tsort ; static ArrayList < ArrayList < Integer > > adj ; static int [ ] visited = new int [ ( int ) 1e5 + 1 ] ; static void dfs ( int u ) { visited [ u ] = 1 ; for ( Integer it : adj . get ( u ) ) { if ( visited [ it ] == 0 ) dfs ( it ) ; } s . push ( u ) ; } static boolean check_cycle ( ) { Map < Integer , Integer > pos = new HashMap < > ( ) ; int ind = 0 ; while ( ! s . isEmpty ( ) ) { pos . put ( s . peek ( ) , ind ) ; tsort . add ( s . peek ( ) ) ; ind += 1 ; s . pop ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( Integer it : adj . get ( i ) ) { if ( pos . get ( i ) > pos . get ( it ) ) { return true ; } } } return false ; } static void addEdge ( int u , int v ) { adj . get ( u ) . add ( v ) ; } public static void main ( String [ ] args ) { n = 4 ; m = 5 ; s = new Stack < > ( ) ; adj = new ArrayList < > ( ) ; tsort = new ArrayList < > ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) adj . add ( new ArrayList < > ( ) ) ; addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 2 ) ; addEdge ( 2 , 0 ) ; addEdge ( 2 , 3 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( visited [ i ] == 0 ) { dfs ( i ) ; } } if ( check_cycle ( ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, it, u
Accumulator variables: i, ind
Iterator variables: i, it
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static class pair { int first , second ; pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void printNewArray ( List < Integer > a , int n ) { List < pair > v = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { v . add ( new pair ( a . get ( i ) , i ) ) ; } Collections . sort ( v , ( pair s1 , pair s2 ) -> { return s1 . first - s2 . first ; } ) ; int ans [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ v . get ( ( i + 1 ) % n ) . second ] = v . get ( i ) . first ; } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( ans [ i ] + " ▁ " ) ; } } public static void main ( String args [ ] ) { List < Integer > a = Arrays . asList ( 4 , 1 , 2 , 5 , 3 ) ; int n = a . size ( ) ; printNewArray ( a , n ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static int min_remove ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { if ( arr [ j ] - arr [ i ] <= k ) { ans = Math . min ( ans , n - j + i - 1 ) ; } } } return ans ; } public static void main ( String [ ] args ) { int k = 3 ; int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; System . out . print ( min_remove ( arr , n , k ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void solve ( int arr [ ] , int n ) { int countzeroes = 0 ; int countones = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) countzeroes ++ ; else countones ++ ; } if ( Math . abs ( countzeroes - countones ) == 1 ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 1 , 0 , 0 , 1 , 1 , 1 } ; int n = arr . length ; solve ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: countones, countzeroes, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static char bs ( char ar [ ] , int n , int ele ) { int start = 0 ; int end = n - 1 ; char ch = ' @ ' ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; if ( ar [ mid ] == ele ) end = mid - 1 ; else if ( ar [ mid ] < ele ) { ch = ar [ mid ] ; start = mid + 1 ; } else end = mid - 1 ; } return ch ; } public static void main ( String [ ] args ) { char ar [ ] = { ' e ' , ' g ' , ' t ' , ' y ' } ; int n = ar . length ; char K = ' u ' ; char ch = bs ( ar , n , K ) ; if ( ch == ' @ ' ) System . out . print ( " - 1" ) ; else System . out . print ( ch ) ; } }

Index/key variables: mid
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findMaxLen ( int [ ] a , int k ) { int n = a . length ; Arrays . sort ( a ) ; boolean [ ] vis = new boolean [ n ] ; HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mp . put ( a [ i ] , i ) ; } int c = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( vis [ i ] == false ) { int check = a [ i ] * k ; if ( mp . containsKey ( check ) ) { c ++ ; vis [ mp . get ( check ) ] = true ; } } } return n - c ; } public static void main ( String [ ] args ) { int K = 3 ; int [ ] arr = { 1 , 4 , 3 , 2 } ; System . out . print ( findMaxLen ( arr , K ) ) ; } }

Index/key variables: i, n
Accumulator variables: c, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class Main { public static int getPrefixLength ( String srcStr , String targetStr ) { if ( targetStr . length ( ) == 0 ) return 0 ; srcStr = srcStr . toLowerCase ( ) ; targetStr = targetStr . toLowerCase ( ) ; HashMap < Character , Integer > dictCount = new HashMap < > ( ) ; int nUnique = 0 ; for ( char ch : targetStr . toCharArray ( ) ) { if ( dictCount . containsKey ( ch ) != true ) { nUnique += 1 ; dictCount . put ( ch , 0 ) ; } dictCount . replace ( ch , dictCount . get ( ch ) + 1 ) ; } for ( int i = 0 ; i < srcStr . length ( ) ; i ++ ) { char ch = srcStr . charAt ( i ) ; if ( dictCount . containsKey ( ch ) != true ) continue ; dictCount . replace ( ch , dictCount . get ( ch ) - 1 ) ; if ( dictCount . get ( ch ) == 0 ) nUnique -= 1 ; if ( nUnique == 0 ) return ( i + 1 ) ; } return - 1 ; } public static void main ( String [ ] args ) { String S = " MarvoloGaunt " ; String T = " Tom " ; System . out . println ( getPrefixLength ( S , T ) ) ; } }

Accumulator variables: i, nUnique
Iterator variables: ch, i
Class/struct names: Main
Java program:
import java . util . * ; class GFG { static boolean check ( char [ ] str , int mid , char a ) { int n = str . length ; int previous = - 1 , i ; for ( i = 0 ; i < n ; ++ i ) { if ( str [ i ] == a ) { if ( i - previous > mid ) { return false ; } previous = i ; } } if ( i - previous > mid ) return false ; else return true ; } static boolean possible ( char [ ] str , int mid ) { for ( int i = 0 ; i < 26 ; ++ i ) { if ( check ( str , mid , ( char ) ( i + ' a ' ) ) ) return true ; } return false ; } static int findMinLength ( char [ ] str ) { int low = 1 , high = str . length ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( possible ( str , mid ) ) high = mid - 1 ; else low = mid + 1 ; } return high + 1 ; } static boolean ifAllDistinct ( String str ) { HashSet < Character > s = new HashSet < Character > ( ) ; for ( char c : str . toCharArray ( ) ) { s . add ( c ) ; } return s . size ( ) == str . length ( ) ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; if ( ifAllDistinct ( str ) ) System . out . print ( - 1 + "NEW_LINE"); else System . out . print ( findMinLength ( str . toCharArray ( ) ) ) ; } }

Index/key variables: i
Iterator variables: c, i
Class/struct names: GFG
Java program:
class GFG { static int solve ( int A [ ] , int N ) { int i = 0 ; int k = 0 ; for ( int j = 1 ; j < N ; j ++ ) { int tempK = Math . min ( A [ i ] , A [ j ] ) / ( j - i ) ; if ( tempK > k ) { k = tempK ; } if ( A [ j ] >= A [ i ] / ( j - i ) ) i = j ; } return k ; } public static void main ( String [ ] args ) { int A [ ] = { 10 , 5 , 12 , 15 , 8 } ; int N = A . length ; System . out . println ( solve ( A , N ) ) ; } }

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

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { public static boolean check ( String str1 , String str2 ) { boolean [ ] mark = new boolean [ 26 ] ; Arrays . fill ( mark , false ) ; int n = str1 . length ( ) , m = str2 . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mark [ str1 . charAt ( i ) - ' a ' ] = true ; } for ( int i = 0 ; i < m ; i ++ ) { if ( mark [ str2 . charAt ( i ) - ' a ' ] ) return true ; } return false ; } public static void main ( String [ ] args ) { String str1 = " abca " , str2 = " efad " ; if ( check ( str1 , str2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void FindPairs ( int n , int k ) { System . out . print ( 1 + " ▁ " + n + "NEW_LINE"); k -- ; for ( long i = 2 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { System . out . print ( 1 + " ▁ " + i + "NEW_LINE"); k -- ; if ( k == 0 ) break ; if ( i != n / i ) { System . out . print ( 1 + " ▁ " + n / i + "NEW_LINE"); k -- ; } if ( k == 0 ) break ; } } } public static void main ( String [ ] args ) { int N = 100 ; int K = 5 ; FindPairs ( N , K ) ; } }

Accumulator variables: i, k
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void dfs ( int u , Vector < Integer > adj [ ] , int [ ] vis , int [ ] inDeg , int [ ] outDeg ) { vis [ u ] = 1 ; for ( int v : adj [ u ] ) { outDeg [ u ] = 1 ; inDeg [ v ] = 1 ; if ( vis [ v ] == 0 ) { dfs ( v , adj , vis , inDeg , outDeg ) ; } } } static int findMinimumEdges ( int source [ ] , int N , int M , int dest [ ] ) { @ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] adj = new Vector [ N + 1 ] ; for ( int i = 0 ; i < adj . length ; i ++ ) adj [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { adj ] . add ( dest [ i ] ) ; } int inDeg [ ] = new int [ N + 1 ] ; int outDeg [ ] = new int [ N + 1 ] ; int vis [ ] = new int [ N + 1 ] ; dfs ( 1 , adj , vis , inDeg , outDeg ) ; int minEdges = 0 ; int totalIndegree = 0 ; int totalOutdegree = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( inDeg [ i ] == 1 ) totalIndegree ++ ; if ( outDeg [ i ] == 1 ) totalOutdegree ++ ; } minEdges = Math . max ( N - totalIndegree , N - totalOutdegree ) ; return minEdges ; } public static void main ( String [ ] args ) { int N = 5 , M = 5 ; int source [ ] = { 1 , 3 , 1 , 3 , 4 } ; int destination [ ] = { 2 , 2 , 3 , 4 , 5 } ; System . out . print ( findMinimumEdges ( source , N , M , destination ) ) ; } }

Index/key variables: i, u, v
Accumulator variables: i, totalIndegree, totalOutdegree
Iterator variables: i, v
Class/struct names: GFG
Java program:
class GFG { static int PermuteTheArray ( int A [ ] , int n ) { int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ A [ i ] - 1 ] = i ; } int mini = n , maxi = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mini = Math . min ( mini , arr [ i ] ) ; maxi = Math . max ( maxi , arr [ i ] ) ; if ( maxi - mini == i ) count ++ ; } return count ; } public static void main ( String [ ] args ) { int A [ ] = { 4 , 5 , 1 , 3 , 2 , 6 } ; System . out . print ( PermuteTheArray ( A , 6 ) ) ; } }

Index/key variables: i, n
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int [ ] findLargest ( int beg , int end , int [ ] arr , int n ) { if ( beg == end ) { int [ ] compared = new int [ n ] ; compared [ 0 ] = 1 ; compared [ 1 ] = arr [ beg ] ; return compared ; } int [ ] compared1 = findLargest ( beg , ( beg + end ) / 2 , arr , n ) ; int [ ] compared2 = findLargest ( ( beg + end ) / 2 + 1 , end , arr , n ) ; if ( compared1 [ 1 ] > compared2 [ 1 ] ) { int k = compared1 [ 0 ] + 1 ; compared1 [ 0 ] = k ; compared1 [ k ] = compared2 [ 1 ] ; return compared1 ; } else { int k = compared2 [ 0 ] + 1 ; compared2 [ 0 ] = k ; compared2 [ k ] = compared1 [ 1 ] ; return compared2 ; } } static void findSecondLargest ( int end , int [ ] arr ) { int [ ] compared1 = findLargest ( 0 , end - 1 , arr , end ) ; int [ ] compared2 = findLargest ( 2 , compared1 [ 0 ] + 2 , compared1 , compared1 [ 0 ] ) ; System . out . print ( compared2 [ 1 ] ) ; } public static void main ( String [ ] args ) { int N = 10 ; int [ ] arr = { 20 , 1990 , 12 , 1110 , 1 , 59 , 12 , 15 , 120 , 1110 } ; findSecondLargest ( N , arr ) ; } }

Index/key variables: beg, k, n
Class/struct names: GFG
Java program:
class GFG { public static int CountsubString ( char [ ] str , int n ) { int c = 0 ; for ( int len = 1 ; len <= n ; len ++ ) { for ( int i = 0 ; i <= n - len ; i ++ ) { int j = i + len - 1 ; char temp = str [ i ] , f = 0 ; if ( j == i ) { c ++ ; continue ; } int k = i + 1 ; while ( temp > str [ k ] && k <= j ) { temp = str [ k ] ; k ++ ; } if ( k > j ) { c ++ ; f = 2 ; } while ( k <= j && temp < str [ k ] && f != 2 ) { temp = str [ k ] ; k ++ ; } if ( k > j && f != 2 ) { c ++ ; f = 0 ; } } } return c ; } public static void main ( String [ ] args ) { char str [ ] = { ' b ' , ' a ' , ' d ' , ' e ' } ; System . out . println ( CountsubString ( str , str . length ) ) ; } }

Index/key variables: i, k
Accumulator variables: c, i, k, len
Iterator variables: i, len
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isSubsetSum ( int arr [ ] , int n , int sum ) { boolean [ ] [ ] subset = new boolean [ n + 1 ] [ sum + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) subset [ i ] [ 0 ] = true ; for ( int i = 1 ; i <= sum ; i ++ ) subset [ 0 ] [ i ] = false ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( j < arr [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; if ( j >= arr [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - arr [ i - 1 ] ] ; } } return subset [ n ] [ sum ] ; } static int findSum ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } int val = ( int ) Math . sqrt ( sum ) ; for ( int i = val ; i >= 0 ; i -- ) { if ( isSubsetSum ( arr , n , i * i ) ) { return i * i ; } } return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ; int n = arr . length ; System . out . println ( findSum ( arr , n ) ) ; } }

Index/key variables: i, j, n, sum
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findsubArray ( int arr [ ] , int N , int K ) { int res = N + 1 ; for ( int i = 0 ; i < N ; i ++ ) { int curr_prod = 1 ; for ( int j = i ; j < N ; j ++ ) { curr_prod = curr_prod * arr [ j ] ; if ( curr_prod % N == K && res > ( j - i + 1 ) ) { res = Math . min ( res , j - i + 1 ) ; break ; } } } return ( res == N + 1 ) ? 0 : res ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 3 } ; int N = arr . length ; int K = 1 ; int answer = findsubArray ( arr , N , K ) ; if ( answer != 0 ) System . out . println ( answer ) ; else System . out . println ( " - 1" ) ; } }

Index/key variables: j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void maximumCount ( int A [ ] , int B [ ] , int n ) { Queue < Integer > q = new LinkedList < > ( ) ; HashSet < Integer > s = new HashSet < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { s . add ( B [ i ] ) ; q . add ( B [ i ] ) ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! s . contains ( A [ i ] ) ) continue ; while ( ! q . isEmpty ( ) && q . peek ( ) != A [ i ] ) { s . remove ( q . peek ( ) ) ; q . remove ( ) ; count ++ ; } if ( A [ i ] == q . peek ( ) ) { q . remove ( ) ; s . remove ( A [ i ] ) ; } if ( q . isEmpty ( ) ) break ; } System . out . print ( count + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 4 ; int A [ ] = { 1 , 2 , 3 , 4 } ; int B [ ] = { 1 , 2 , 4 , 3 } ; maximumCount ( A , B , N ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { final static int N = 3 , M = 3 ; static boolean checkBitonic ( int arr [ ] , int n ) { int i , j , f = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { f = 1 ; break ; } } if ( i == n ) return true ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] < arr [ j - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { if ( f == 1 ) return false ; } } return true ; } static void check ( int arr [ ] [ ] ) { int f = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! checkBitonic ( arr [ i ] , M ) ) { System . out . println ( " NO " ) ; return ; } } for ( int i = 0 ; i < N ; i ++ ) { int temp [ ] = new int [ N ] ; for ( int j = 0 ; j < N ; j ++ ) { temp [ j ] = arr [ j ] [ i ] ; } if ( ! checkBitonic ( temp , N ) ) { System . out . println ( " NO " ) ; return ; } } System . out . println ( " YES " ) ; } public static void main ( String [ ] args ) { int m [ ] [ ] = { { 1 , 2 , 3 } , { 3 , 4 , 5 } , { 2 , 6 , 4 } } ; check ( m ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int getMaxGcd ( int N ) { int maxGcd = Integer . MIN_VALUE , A , B ; for ( int i = 1 ; i <= Math . sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { A = i ; B = N / i ; maxGcd = Math . max ( maxGcd , gcd ( A , B ) ) ; } } return maxGcd ; } public static void main ( String s [ ] ) { int N = 18 ; System . out . println ( getMaxGcd ( N ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean can_place ( int A [ ] , int n , int B , int mid ) { int count = 1 ; int last_position = A [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( A [ i ] - last_position >= mid ) { last_position = A [ i ] ; count ++ ; if ( count == B ) { return true ; } } } return false ; } static int find_min_difference ( int A [ ] , int n , int B ) { Arrays . sort ( A ) ; int s = 0 ; int e = A [ n - 1 ] - A [ 0 ] ; int ans = 0 ; while ( s <= e ) { int mid = ( s + e ) / 2 ; if ( can_place ( A , n , B , mid ) ) { ans = mid ; s = mid + 1 ; } else { e = mid - 1 ; } } return ans ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 3 , 5 } ; int n = A . length ; int B = 3 ; int min_difference = find_min_difference ( A , n , B ) ; System . out . print ( min_difference ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countTriplets ( int A [ ] , int N ) { int ans = 0 ; HashMap < Integer , Integer > map = new HashMap < Integer , Integer > ( ) ; for ( int j = N - 2 ; j >= 1 ; j -- ) { if ( map . containsKey ( A [ j + 1 ] ) ) map . put ( A [ j + 1 ] , map . get ( A [ j + 1 ] ) + 1 ) ; else map . put ( A [ j + 1 ] , 1 ) ; for ( int i = 0 ; i < j ; i ++ ) { int target = A [ i ] * A [ j ] ; if ( map . containsKey ( target ) ) ans += map . get ( target ) ; } } return ans ; } public static void main ( String [ ] args ) { int N = 5 ; int A [ ] = { 2 , 3 , 4 , 6 , 12 } ; System . out . print ( countTriplets ( A , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void MissingPoint ( Vector < pair > V , int N ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < V . size ( ) ; i ++ ) { if ( mp . containsKey ( V . get ( i ) . first ) ) mp . put ( V . get ( i ) . first , V . get ( i ) . first + 1 ) ; else mp . put ( V . get ( i ) . first , 1 ) ; } int x = 0 , y = 0 ; for ( Map . Entry < Integer , Integer > it : mp . entrySet ( ) ) { if ( it . getValue ( ) % 2 == 1 ) { x = it . getKey ( ) ; break ; } } mp . clear ( ) ; for ( int i = 0 ; i < V . size ( ) ; i ++ ) { if ( mp . containsKey ( V . get ( i ) . second ) ) mp . put ( V . get ( i ) . second , V . get ( i ) . second + 1 ) ; else mp . put ( V . get ( i ) . second , 1 ) ; } for ( Map . Entry < Integer , Integer > it : mp . entrySet ( ) ) { if ( it . getValue ( ) % 2 == 1 ) { y = it . getKey ( ) ; break ; } } System . out . print ( x + " ▁ " + y ) ; } public static void main ( String [ ] args ) { int N = 2 ; Vector < pair > V = new Vector < pair > ( ) ; V . add ( new pair ( 1 , 1 ) ) ; V . add ( new pair ( 1 , 2 ) ) ; V . add ( new pair ( 4 , 6 ) ) ; V . add ( new pair ( 2 , 1 ) ) ; V . add ( new pair ( 9 , 6 ) ) ; V . add ( new pair ( 9 , 3 ) ) ; V . add ( new pair ( 4 , 3 ) ) ; MissingPoint ( V , N ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static int sign ( int x ) { if ( x > 0 ) return 1 ; else return - 1 ; } static int findMaxSum ( int arr [ ] , int size ) { int max_sum = 0 , pres , i , j ; for ( i = 0 ; i < size ; i ++ ) { pres = arr [ i ] ; j = i ; while ( j < size && sign ( arr [ i ] ) == sign ( arr [ j ] ) ) { pres = Math . max ( pres , arr [ j ] ) ; j ++ ; } max_sum = max_sum + pres ; i = j - 1 ; } return max_sum ; } public static void main ( String [ ] args ) { int arr [ ] = { - 2 , 8 , 3 , 8 , - 4 , - 15 , 5 , - 2 , - 3 , 1 } ; int size = arr . length ; System . out . println ( findMaxSum ( arr , size ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean groupInKConsecutive ( int [ ] arr , int K ) { HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ; for ( int h : arr ) { if ( count . containsKey ( h ) ) count . put ( h , count . get ( h ) + 1 ) ; else count . put ( h , 1 ) ; } for ( Map . Entry < Integer , Integer > c : count . entrySet ( ) ) { int cur = c . getKey ( ) ; int n = c . getValue ( ) ; if ( n > 0 ) { for ( int i = 1 ; i < K ; ++ i ) { if ( ! count . containsKey ( cur + i ) ) { return false ; } count . put ( cur + i , count . get ( cur + i ) - n ) ; if ( count . get ( cur + i ) < 0 ) return false ; } } } return true ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 6 , 2 , 3 , 4 , 7 , 8 } ; int k = 3 ; if ( groupInKConsecutive ( arr , k ) ) { System . out . print ( " True " ) ; } else { System . out . print ( " False " ) ; } } }

Iterator variables: h, i
Class/struct names: GFG