dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; class GFG { static void mergeTwoHalf ( int [ ] A , int n ) { int i ; int [ ] temp = new int [ n ] ; for ( i = 0 ; i < n - 1 ; i ++ ) { if ( A [ i ] > A [ i + 1 ] ) { half_i = i + 1 ; break ; } } if ( half_i == 0 ) return ; i = 0 ; int j = half_i ; int k = 0 ; while ( i < half_i && j < n ) { if ( A [ i ] < A [ j ] ) temp [ k ++ ] = A [ i ++ ] ; else temp [ k ++ ] = A [ j ++ ] ; } while ( i < half_i ) temp [ k ++ ] = A [ i ++ ] ; while ( j < n ) temp [ k ++ ] = A [ j ++ ] ; for ( i = 0 ; i < n ; i ++ ) A [ i ] = temp [ i ] ; } static public void main ( String [ ] args ) { int [ ] A = { 2 , 3 , 8 , - 1 , 7 , 10 } ; int n = A . length ; mergeTwoHalf ( A , n ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( A [ i ] + " ▁ " ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j, k
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findMinDiff ( int arr [ ] , int n , int m ) { if ( m == 0 n == 0 ) return 0 ; Arrays . sort ( arr ) ; if ( n < m ) return - 1 ; int min_diff = Integer . MAX_VALUE ; for ( int i = 0 ; i + m - 1 < n ; i ++ ) { int diff = arr [ i + m - 1 ] - arr [ i ] ; if ( diff < min_diff ) min_diff = diff ; } return min_diff ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 4 , 7 , 9 , 2 , 23 , 25 , 41 , 30 , 40 , 28 , 42 , 30 , 44 , 48 , 43 , 50 } ; int n = arr . length ; System . out . println ( " Minimum ▁ difference ▁ is ▁ " + findMinDiff ( arr , n , m ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int distinctCount ( int arr [ ] , int n ) { Set < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) s . add ( Math . abs ( arr [ i ] ) ) ; return s . size ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 2 , - 1 , 0 , 1 , 1 } ; int n = arr . length ; System . out . println ( " Count ▁ of ▁ absolute ▁ distinct ▁ values ▁ : ▁ " + distinctCount ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int distinctCount ( int arr [ ] , int n ) { int count = n ; int i = 0 , j = n - 1 , sum = 0 ; while ( i < j ) { while ( i != j && arr [ i ] == arr [ i + 1 ] ) { count -- ; i ++ ; } while ( i != j && arr [ j ] == arr [ j - 1 ] ) { count -- ; j -- ; } if ( i == j ) break ; sum = arr [ i ] + arr [ j ] ; if ( sum == 0 ) { count -- ; i ++ ; j -- ; } else if ( sum < 0 ) i ++ ; else j -- ; } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { - 2 , - 1 , 0 , 1 , 1 } ; int n = arr . length ; System . out . println ( " Count ▁ of ▁ absolute ▁ distinct ▁ values ▁ : ▁ " + distinctCount ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Class/struct names: GFG
Java program:
class GFG { static int MAX = 100 ; public static void sortStrings ( String [ ] arr , int n ) { String temp ; for ( int j = 0 ; j < n - 1 ; j ++ ) { for ( int i = j + 1 ; i < n ; i ++ ) { if ( arr [ j ] . compareTo ( arr [ i ] ) > 0 ) { temp = arr [ j ] ; arr [ j ] = arr [ i ] ; arr [ i ] = temp ; } } } } public static void main ( String [ ] args ) { String [ ] arr = { " GeeksforGeeks " , " Quiz " , " Practice " , " Gblogs " , " Coding " } ; int n = arr . length ; sortStrings ( arr , n ) ; System . out . println ( " Strings ▁ in ▁ sorted ▁ order ▁ are ▁ : ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . println ( " String ▁ " + ( i + 1 ) + " ▁ is ▁ " + arr [ i ] ) ; } }

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 sortByOneSwap ( int arr [ ] , int n ) { for ( int i = n - 1 ; i > 0 ; i -- ) { if ( arr [ i ] < arr [ i - 1 ] ) { int j = i - 1 ; while ( j >= 0 && arr [ i ] < arr [ j ] ) j -- ; int temp = arr [ i ] ; arr [ i ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; break ; } } } static void printArray ( int arr [ ] , int n ) { int i ; for ( i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 30 , 20 , 40 , 50 , 60 , 70 } ; int n = arr . length ; System . out . println ( " Given ▁ array ▁ is ▁ " ) ; printArray ( arr , n ) ; sortByOneSwap ( arr , n ) ; System . out . println ( " Sorted ▁ array ▁ is ▁ " ) ; printArray ( arr , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class PancakeSort { static void flip ( int arr [ ] , int i ) { int temp , start = 0 ; while ( start < i ) { temp = arr [ start ] ; arr [ start ] = arr [ i ] ; arr [ i ] = temp ; start ++ ; i -- ; } } static int findMax ( int arr [ ] , int n ) { int mi , i ; for ( mi = 0 , i = 0 ; i < n ; ++ i ) if ( arr [ i ] > arr [ mi ] ) mi = i ; return mi ; } static int pancakeSort ( int arr [ ] , int n ) { for ( int curr_size = n ; curr_size > 1 ; -- curr_size ) { int mi = findMax ( arr , curr_size ) ; if ( mi != curr_size - 1 ) { flip ( arr , mi ) ; flip ( arr , curr_size - 1 ) ; } } return 0 ; } static void printArray ( int arr [ ] , int arr_size ) { for ( int i = 0 ; i < arr_size ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; System . out . println ( " " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 23 , 10 , 20 , 11 , 12 , 6 , 7 } ; int n = arr . length ; pancakeSort ( arr , n ) ; System . out . println ( " Sorted ▁ Array : ▁ " ) ; printArray ( arr , n ) ; } }

Index/key variables: i, mi, start
Accumulator variables: i, start
Iterator variables: curr_size, i, mi
Class/struct names: PancakeSort
Java program:
import java . util . * ; class GFG { static String performOperation ( char [ ] S , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { if ( S [ i ] == ' a ' ) { S [ i ] = ' b ' ; } else { S [ i ] = ' a ' ; } } else { if ( S [ i ] == ' z ' ) { S [ i ] = ' y ' ; } else { S [ i ] = ' z ' ; } } } return String . valueOf ( S ) ; } public static void main ( String [ ] args ) { String S = " giad " ; int N = S . length ( ) ; System . out . print ( performOperation ( S . toCharArray ( ) , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean check ( int x , int N ) { while ( true ) { N -= x ; if ( x < 10 ) break ; int temp2 = 0 ; while ( x > 0 ) { temp2 += ( x % 10 ) ; x = ( int ) x / 10 ; } x = temp2 ; } if ( ( x < 10 ) && ( N == 0 ) ) { return true ; } return false ; } static int countNoOfsuchX ( int N ) { int k = ( int ) ( Math . log10 ( N ) ) + 1 ; int count = 1 ; for ( int x = ( N - ( k * ( k + 1 ) * 5 ) ) ; x <= N ; x ++ ) { if ( check ( x , N ) ) { count += 1 ; } } return count ; } public static void main ( String [ ] args ) { int N = 9399 ; System . out . println ( countNoOfsuchX ( N ) ) ; } }

Accumulator variables: N, count, temp2, x
Iterator variables: x
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static long proc ( List < Integer > v ) { int n = v . size ( ) ; int low = v . get ( n - 1 ) , high = v . get ( n - 1 ) ; int p1 = n , p2 = n ; long ans = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { int x = v . get ( i ) ; if ( x < low ) { low = x ; ans = 0 ; } else if ( x > high ) { high = x ; ans = 0 ; } if ( x == low ) p1 = i ; if ( x == high ) p2 = i ; ans += n - Math . max ( p1 , p2 ) ; } return ans ; } static long subarray ( List < Integer > v ) { int n = v . size ( ) ; if ( n <= 1 ) return n ; long ans = proc ( v ) ; int low = v . get ( 0 ) , pos_low = 0 ; int high = v . get ( 0 ) , pos_high = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int x = v . get ( i ) ; if ( x < low ) { low = x ; pos_low = i ; } else if ( x > high ) { high = x ; pos_high = i ; } } List < Integer > u = new ArrayList < > ( Collections . nCopies ( n , 0 ) ) ; Collections . copy ( u , v ) ; u . remove ( pos_low ) ; ans = Math . max ( ans , proc ( u ) ) ; List < Integer > w = new ArrayList < > ( Collections . nCopies ( n , 0 ) ) ; Collections . copy ( w , v ) ; w . remove ( pos_high ) ; return Math . max ( ans , proc ( w ) ) ; } public static void main ( String [ ] args ) { List < Integer > arr = Arrays . asList ( 7 , 2 , 5 , 4 , 3 , 1 ) ; System . out . println ( subarray ( arr ) ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int find ( ArrayList < Integer > arr , int N ) { int Sum = 0 ; for ( int item : arr ) Sum += item ; if ( Sum % N == 1 ) return - 1 ; int k = Sum / N ; int ans = 0 ; int i = 0 ; while ( i < N ) { ans = ans + Math . abs ( k - arr . get ( i ) ) ; i += 1 ; } return ans / 2 ; } public static void main ( String [ ] args ) { ArrayList < Integer > arr = new ArrayList < > ( ) ; arr . add ( 5 ) ; arr . add ( 4 ) ; arr . add ( 1 ) ; arr . add ( 10 ) ; int N = arr . size ( ) ; System . out . println ( find ( arr , N ) ) ; } }

Accumulator variables: Sum, i
Iterator variables: item
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int minimumSteps ( int a , int b ) { int cnt = 0 ; a = Math . abs ( a - b ) ; cnt = ( a / 5 ) + ( a % 5 ) / 2 + ( a % 5 ) % 2 ; return cnt ; } public static void main ( String [ ] args ) { int A = 3 , B = 9 ; System . out . println ( minimumSteps ( A , B ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int shortestDistance ( String s , int n ) { int [ ] visited = new int [ 128 ] ; Arrays . fill ( visited , - 1 ) ; int ans = Integer . MAX_VALUE ; for ( int right = 0 ; right < n ; right ++ ) { char c = s . charAt ( right ) ; int left = visited ; if ( left != - 1 ) ans = Math . min ( ans , right - left - 1 ) ; visited = right ; } return ans == Integer . MAX_VALUE ? - 1 : ans ; } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; int n = 13 ; System . out . print ( shortestDistance ( s , n ) ) ; } }

Accumulator variables: right
Iterator variables: right
Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { static String smallestNonSubsequence ( String S , int N ) { int freq = 0 ; for ( int i = 0 ; i < N ; i ++ ) if ( S . charAt ( i ) == ' a ' ) freq ++ ; String ans = " " ; for ( int i = 0 ; i < f req ; i ++ ) { ans += ' a ' ; } if ( freq == N ) ans = ans . replace ( ans . charAt ( freq - 1 ) , ' b ' ) ; else ans += ' a ' ; return ans ; } public static void main ( String args [ ] ) { String S = " abcdefghijklmnopqrstuvwxyz " ; int N = S . length ( ) ; System . out . println ( smallestNonSubsequence ( S , N ) ) ; } }

Accumulator variables: ans, freq, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static final double Pi = 3.141592 ; static int MaxBuildingsCovered ( int arr [ ] , int N , int L ) { double curr_sum = 0 ; int start = 0 , curr_count = 0 , max_count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { curr_sum = curr_sum + ( ( double ) arr [ i ] * Pi ) ; if ( i != 0 ) curr_sum += 1 ; if ( curr_sum <= L ) { curr_count ++ ; } else if ( curr_sum > L ) { curr_sum = curr_sum - ( ( double ) arr [ start ] * Pi ) ; curr_sum -= 1 ; start ++ ; curr_count -- ; } max_count = Math . max ( curr_count , max_count ) ; } return max_count ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 1 , 6 , 2 } ; int L = 24 ; int N = arr . length ; System . out . println ( MaxBuildingsCovered ( arr , N , L ) ) ; } }

Index/key variables: i, start
Accumulator variables: curr_count, curr_sum, i, start
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countUnsetBits ( int N ) { int c = 0 ; while ( N != 0 ) { if ( N % 2 == 0 ) { c += 1 ; } N = N >> 1 ; } return c ; } static void countBitwiseZero ( int N ) { int unsetBits = countUnsetBits ( N ) ; System . out . print ( 1 << unsetBits ) ; } public static void main ( String [ ] args ) { int N = 9 ; countBitwiseZero ( N ) ; } }

Accumulator variables: c
Class/struct names: GFG
Java program:
public class MyClass { static boolean isPossible ( String s ) { int n = s . length ( ) ; int count_0 = 0 , count_1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == '0' ) ++ count_0 ; else ++ count_1 ; if ( count_1 > count_0 ) return false ; } if ( count_0 != ( 2 * count_1 ) ) return false ; count_0 = 0 ; count_1 = 0 ; for ( int i = n - 1 ; i >= 0 ; -- i ) { if ( s . charAt ( i ) == '0' ) ++ count_0 ; else ++ count_1 ; if ( count_1 > count_0 ) return false ; } return true ; } public static void main ( String args [ ] ) { String s = "010100" ; if ( isPossible ( s ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: MyClass
Java program:
import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; public class GFG { static void leastBricks ( ArrayList < ArrayList < Integer > > wall ) { HashMap < Integer , Integer > map = new HashMap < > ( ) ; int res = 0 ; for ( ArrayList < Integer > list : wall ) { int width = 0 ; for ( int i = 0 ; i < list . size ( ) - 1 ; i ++ ) { width += list . get ( i ) ; map . put ( width , map . getOrDefault ( width , 0 ) + 1 ) ; res = Math . max ( res , map . getOrDefault ( width , 0 ) ) ; } } System . out . println ( wall . size ( ) - res ) ; } public static void main ( String [ ] args ) { ArrayList < ArrayList < Integer > > arr = new ArrayList < > ( ) ; arr . add ( new ArrayList < > ( Arrays . asList ( 1 , 2 , 2 , 1 ) ) ) ; arr . add ( new ArrayList < > ( Arrays . asList ( 3 , 1 , 2 ) ) ) ; arr . add ( new ArrayList < > ( Arrays . asList ( 1 , 3 , 2 ) ) ) ; arr . add ( new ArrayList < > ( Arrays . asList ( 2 , 4 ) ) ) ; arr . add ( new ArrayList < > ( Arrays . asList ( 3 , 1 , 2 ) ) ) ; arr . add ( new ArrayList < > ( Arrays . asList ( 1 , 3 , 1 , 1 ) ) ) ; leastBricks ( arr ) ; } }

Accumulator variables: i, width
Iterator variables: i, list
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findPermutation ( int N ) { for ( int i = 1 ; i <= N ; i ++ ) System . out . print ( i + " ▁ " ) ; } public static void main ( String [ ] args ) { int N = 5 ; findPermutation ( N ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int numberOfWays ( int N , int X , int Y ) { int S1 = ( N - 1 ) * X + Y ; int S2 = ( N - 1 ) * Y + X ; return ( S2 - S1 + 1 ) ; } public static void main ( String [ ] args ) { int N = 3 ; int X = 13 ; int Y = 15 ; System . out . println ( numberOfWays ( N , X , Y ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int MinimumOperations ( int [ ] A , int N , int K ) { int Count = 0 ; int i = 0 ; while ( i < N - 1 ) { i = i + K - 1 ; Count ++ ; } return Count ; } public static void main ( String [ ] args ) { int [ ] A = { 5 , 4 , 3 , 1 , 2 } ; int K = 3 ; int N = A . length ; System . out . println ( MinimumOperations ( A , N , K ) ) ; } }

Accumulator variables: Count
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static boolean is_prime ( long n ) { if ( n == 1 ) { return false ; } for ( long i = 2 ; i <= ( long ) Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { return false ; } } return true ; } static void consecutive_primes ( long n ) { long first = - 1 , second = - 1 ; for ( long i = ( long ) Math . sqrt ( n ) ; i >= 2 ; i -- ) { if ( is_prime ( i ) ) { first = i ; break ; } } for ( long i = ( long ) Math . sqrt ( n ) + 1 ; i <= n / 2 ; i ++ ) { if ( is_prime ( i ) ) { second = i ; break ; } } if ( first * second >= n ) { System . out . println ( first + " ▁ " + second ) ; } else { for ( long i = second + 1 ; i <= n ; i ++ ) { if ( is_prime ( i ) ) { System . out . println ( second + " ▁ " + i ) ; return ; } } } } public static void main ( String args [ ] ) { long n = 14 ; consecutive_primes ( n ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static String construct_digits ( String s ) { char [ ] k = { ' z ' , ' w ' , ' u ' , ' x ' , ' g ' , ' h ' , ' o ' , ' f ' , ' v ' , ' i ' } ; String [ ] l = { " zero " , " two " , " four " , " six " , " eight " , " three " , " one " , " five " , " seven " , " nine " } ; int [ ] c = { 0 , 2 , 4 , 6 , 8 , 3 , 1 , 5 , 7 , 9 } ; List < Integer > ans = new ArrayList < > ( ) ; HashMap < Character , Integer > d = new HashMap < > ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { d . put ( s . charAt ( i ) , d . getOrDefault ( s . charAt ( i ) , 0 ) + 1 ) ; } for ( int i = 0 ; i < k . length ; i ++ ) { int x = 0 ; if ( d . containsKey ( k [ i ] ) ) x = d . get ( k [ i ] ) ; for ( int j = 0 ; j < l [ i ] . length ( ) ; j ++ ) { if ( d . containsKey ( l [ i ] . charAt ( j ) ) ) d . put ( l [ i ] . charAt ( j ) , d . get ( l [ i ] . charAt ( j ) ) - x ) ; } for ( int j = 0 ; j < x ; j ++ ) ans . add ( c [ i ] ) ; } Collections . sort ( ans ) ; String str = " " ; for ( int val : ans ) str += val ; return str ; } public static void main ( String [ ] args ) { String s = " fviefuro " ; System . out . println ( construct_digits ( s ) ) ; } }

Index/key variables: i
Accumulator variables: i, j, str
Iterator variables: i, j, val
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void countDecrements ( long arr [ ] [ ] ) { int n = arr . length ; int m = arr [ 0 ] . length ; int count_1 = 0 ; int count_2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( ( i + j ) % 2 == arr [ i ] [ j ] % 2 ) count_1 ++ ; if ( 1 - ( i + j ) % 2 == arr [ i ] [ j ] % 2 ) count_2 ++ ; } } System . out . println ( Math . min ( count_1 , count_2 ) ) ; } public static void main ( String [ ] args ) { long arr [ ] [ ] = { { 1 , 2 , 3 } , { 1 , 2 , 3 } , { 1 , 2 , 3 } } ; countDecrements ( arr ) ; } }

Index/key variables: i, j
Accumulator variables: count_1, count_2, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void check ( int X , int Y ) { if ( X > 3 ) { System . out . print ( " Yes " ) ; } else if ( X == 1 && Y == 1 ) { System . out . print ( " Yes " ) ; } else if ( X == 2 && Y <= 3 ) { System . out . print ( " Yes " ) ; } else if ( X == 3 && Y <= 3 ) { System . out . print ( " Yes " ) ; } else { System . out . print ( " No " ) ; } } public static void main ( String [ ] args ) { int X = 6 , Y = 8 ; check ( X , Y ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int distIntegers ( int L , int R ) { return 2 * R - 2 * L + 1 ; } public static void main ( String [ ] args ) { int L = 3 , R = 8 ; System . out . println ( distIntegers ( L , R ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void evenXorSubarray ( int arr [ ] , int n ) { int ans = 0 ; int freq [ ] = { 0 , 0 } ; int XOR = 0 ; for ( int i = 0 ; i < n ; i ++ ) { XOR = XOR ^ arr [ i ] ; if ( XOR % 2 == 0 ) { ans += freq [ 0 ] + 1 ; freq [ 0 ] ++ ; } else { ans += freq [ 1 ] ; freq [ 1 ] ++ ; } } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = arr . length ; evenXorSubarray ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int countOccurrences ( int N , int X ) { int count = 0 ; for ( int i = 1 ; i < Math . sqrt ( X ) ; i ++ ) { if ( X % i == 0 ) { int a = i ; int b = X / i ; if ( a <= N && b <= N ) { if ( a == b ) count += 1 ; else count += 2 ; } } } return count ; } public static void main ( String [ ] args ) { int N = 7 ; int X = 12 ; System . out . println ( countOccurrences ( N , X ) ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void findArrayWithMaxProduct ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) if ( arr [ i ] >= 0 ) { arr [ i ] = - arr [ i ] - 1 ; } if ( N % 2 == 1 ) { int max_element = - 1 ; int index = - 1 ; for ( int i = 0 ; i < N ; i ++ ) if ( Math . abs ( arr [ i ] ) > max_element ) { max_element = Math . abs ( arr [ i ] ) ; index = i ; } arr [ index ] = - arr [ index ] - 1 ; } for ( int i = 0 ; i < N ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { - 3 , 0 , 1 } ; int N = arr . length ; findArrayWithMaxProduct ( arr , N ) ; } }

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findPerfectIndex ( int N , int K ) { int i = 0 ; for ( ; i < K ; i ++ ) { System . out . print ( ( N - K + 1 ) + i + " ▁ " ) ; } for ( ; i < N ; i ++ ) { System . out . print ( i - K + 1 + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 10 , K = 3 ; findPerfectIndex ( N , K ) ; } }

Accumulator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void countPairs ( long L , long R ) { long firstNum = 2 * L ; long lastNum = 2 * R ; long Cntpairs = lastNum - firstNum + 1 ; System . out . println ( Cntpairs ) ; } public static void main ( String [ ] args ) { long L = 2 , R = 3 ; countPairs ( L , R ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void countPairs ( int A [ ] , int n ) { int count = ( n * ( n - 1 ) ) / 2 ; Map < Integer , Integer > mp = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . containsKey ( A [ i ] ) ) { mp . put ( A [ i ] , mp . get ( A [ i ] ) + 1 ) ; } else { mp . put ( A [ i ] , 1 ) ; } } for ( Map . Entry < Integer , Integer > it : mp . entrySet ( ) ) { int c = it . getValue ( ) ; count = count - ( c * ( c - 1 ) ) / 2 ; } System . out . print ( count ) ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 4 , 7 } ; int N = A . length ; countPairs ( A , N ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static String check ( int current_row , int current_col , int destination_row , int destination_col ) { if ( current_row == destination_row ) return " POSSIBLE " ; else if ( current_col == destination_col ) return " POSSIBLE " ; else return " NOT ▁ POSSIBLE " ; } public static void main ( String [ ] args ) { int current_row = 8 ; int current_col = 8 ; int destination_row = 8 ; int destination_col = 4 ; String output = check ( current_row , current_col , destination_row , destination_col ) ; System . out . println ( output ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int isDiv ( int N , int X , int M , int res ) { if ( X == 0 ) { if ( N % M == 0 ) { res = N ; return res ; } return res ; } for ( int i = 0 ; i < 9 ; i ++ ) { int temp = isDiv ( N * 10 + i , X - 1 , M , res ) ; if ( temp != - 1 ) { return temp ; } } return res ; } public static void main ( String [ ] args ) throws java . lang . Exception { int N = 4 , M = 50 , X = 2 ; int res = - 1 ; res = isDiv ( N , X , M , res ) ; System . out . println ( res ) ; } }

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