dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int findNumber ( pair a [ ] , int n , int K ) { int low = 0 , high = n - 1 ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( K >= a [ mid ] . first && K <= a [ mid ] . second ) return mid ; else if ( K < a [ mid ] . first ) high = mid - 1 ; else low = mid + 1 ; } return - 1 ; } public static void main ( String [ ] args ) { pair a [ ] = { new pair ( 1 , 3 ) , new pair ( 4 , 7 ) , new pair ( 8 , 11 ) } ; int n = a . length ; int k = 6 ; int index = findNumber ( a , n , k ) ; if ( index != - 1 ) System . out . println ( index ) ; else System . out . println ( - 1 ) ; } }

Index/key variables: mid
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static void prefixSum ( int [ ] p_arr , int [ ] arr , int n ) { p_arr [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) p_arr [ i ] = arr [ i ] + p_arr [ i - 1 ] ; } static void qPrefixSum ( int [ ] p_arr , int n , HashSet < Integer > q ) { for ( int i = 0 ; i < n ; i ++ ) q . add ( p_arr [ i ] ) ; } static void canDivide ( int [ ] p_arr , int n , HashSet < Integer > q , int l , int r ) { int sum ; if ( l == 0 ) sum = p_arr [ r ] ; else sum = p_arr [ r ] - p_arr [ l - 1 ] ; if ( sum % 2 == 1 ) { System . out . println ( " No " ) ; return ; } int beg = 0 ; if ( l != 0 ) beg = p_arr [ l - 1 ] ; if ( q . contains ( beg + sum / 2 ) && ( beg + sum / 2 ) != ( int ) q . toArray ( ) [ q . size ( ) - 1 ] ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 2 , 3 } ; int n = arr . length ; int p_arr [ ] = new int [ n ] ; prefixSum ( p_arr , arr , n ) ; HashSet < Integer > q = new HashSet < > ( ) ; qPrefixSum ( p_arr , n , q ) ; canDivide ( p_arr , n , q , 0 , 1 ) ; canDivide ( p_arr , n , q , 1 , 3 ) ; canDivide ( p_arr , n , q , 1 , 2 ) ; } }

Index/key variables: i, n, r
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { final static int n = 4 ; static int findRing ( int arr [ ] [ ] , int x ) { if ( arr [ 0 ] [ 0 ] > x ) return - 1 ; int l = 0 , r = ( n + 1 ) / 2 - 1 ; if ( n % 2 == 1 && arr [ r ] [ r ] < x ) return - 1 ; if ( n % 2 == 0 && arr [ r + 1 ] [ r ] < x ) return - 1 ; while ( l < r ) { int mid = ( l + r ) / 2 ; if ( arr [ mid ] [ mid ] <= x ) if ( mid == ( n + 1 ) / 2 - 1 arr [ mid + 1 ] [ mid + 1 ] > x ) return mid ; else l = mid + 1 ; else r = mid - 1 ; } return r ; } static int binarySearchRowInc ( int arr [ ] [ ] , int row , int l , int r , int x ) { while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( arr [ row ] [ mid ] == x ) return mid ; if ( arr [ row ] [ mid ] < x ) l = mid + 1 ; else r = mid - 1 ; } return - 1 ; } static int binarySearchColumnInc ( int arr [ ] [ ] , int col , int t , int b , int x ) { while ( t <= b ) { int mid = ( t + b ) / 2 ; if ( arr [ mid ] [ col ] == x ) return mid ; if ( arr [ mid ] [ col ] < x ) t = mid + 1 ; else b = mid - 1 ; } return - 1 ; } static int binarySearchRowDec ( int arr [ ] [ ] , int row , int l , int r , int x ) { while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( arr [ row ] [ mid ] == x ) return mid ; if ( arr [ row ] [ mid ] < x ) r = mid - 1 ; else l = mid + 1 ; } return - 1 ; } static int binarySearchColumnDec ( int arr [ ] [ ] , int col , int t , int b , int x ) { while ( t <= b ) { int mid = ( t + b ) / 2 ; if ( arr [ mid ] [ col ] == x ) return mid ; if ( arr [ mid ] [ col ] < x ) b = mid - 1 ; else t = mid + 1 ; } return - 1 ; } static void spiralBinary ( int arr [ ] [ ] , int x ) { int f1 = findRing ( arr , x ) ; int r , c ; if ( f1 == - 1 ) { System . out . print ( " - 1" ) ; return ; } if ( n % 2 == 1 && f1 == ( n + 1 ) / 2 - 1 ) { System . out . println ( f1 + " ▁ " + f1 ) ; return ; } if ( x < arr [ f1 ] [ n - f1 - 1 ] ) { c = binarySearchRowInc ( arr , f1 , f1 , n - f1 - 2 , x ) ; r = f1 ; } else if ( x < arr [ n - f1 - 1 ] [ n - f1 - 1 ] ) { c = n - f1 - 1 ; r = binarySearchColumnInc ( arr , n - f1 - 1 , f1 , n - f1 - 2 , x ) ; } else if ( x < arr [ n - f1 - 1 ] [ f1 ] ) { c = binarySearchRowDec ( arr , n - f1 - 1 , f1 + 1 , n - f1 - 1 , x ) ; r = n - f1 - 1 ; } else { r = binarySearchColumnDec ( arr , f1 , f1 + 1 , n - f1 - 1 , x ) ; c = f1 ; } if ( c == - 1 r == - 1 ) System . out . print ( " - 1" ) ; else System . out . print ( r + " ▁ " + c ) ; return ; } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 1 , 2 , 3 , 4 } , { 12 , 13 , 14 , 5 } , { 11 , 16 , 15 , 6 } , { 10 , 9 , 8 , 7 } } ; spiralBinary ( arr , 7 ) ; } }

Index/key variables: col, f1, mid, r, row
Class/struct names: GFG
Java program:
public class GFG { static int costToPanagram ( String str , int cost [ ] ) { int i , n = str . length ( ) ; int occurrences [ ] = new int [ 26 ] ; for ( i = 0 ; i < n ; i ++ ) occurrences [ str . charAt ( i ) - ' a ' ] ++ ; int gain = 0 ; for ( i = 0 ; i < 26 ; i ++ ) { if ( occurrences [ i ] == 0 ) gain -= ( 2 * cost [ i ] ) ; else if ( occurrences [ i ] > 1 ) gain += ( cost [ i ] * ( occurrences [ i ] - 1 ) ) ; } if ( gain >= 0 ) return 0 ; return ( gain * - 1 ) ; } public static void main ( String [ ] args ) { int cost [ ] = { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 } ; String str = " geeksforgeeks " ; System . out . println ( costToPanagram ( str , cost ) ) ; } }

Index/key variables: i
Accumulator variables: gain, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . HashMap ; import java . util . Map ; class GfG { static int strScore ( String str [ ] , String s , int n ) { HashMap < String , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) m . put ( str [ i ] , i + 1 ) ; if ( ! m . containsKey ( s ) ) return 0 ; int score = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) score += s . charAt ( i ) - ' a ' + 1 ; score = score * m . get ( s ) ; return score ; } public static void main ( String [ ] args ) { String str [ ] = { " geeksforgeeks " , " algorithms " , " stack " } ; String s = " algorithms " ; int n = str . length ; System . out . println ( strScore ( str , s , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, score
Iterator variables: i
Class/struct names: GfG
Java program:
import java . util . * ; class solution { static int countSubArrays ( int arr [ ] , int n , int K ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { int bitwise_or = 0 ; for ( int k = i ; k <= j ; k ++ ) { bitwise_or = bitwise_or | arr [ k ] ; } if ( bitwise_or >= K ) count ++ ; } } return count ; } public static void main ( String args [ ] ) { int arr [ ] = { 3 , 4 , 5 } ; int n = arr . length ; int k = 6 ; System . out . println ( countSubArrays ( arr , n , k ) ) ; } }

Index/key variables: k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Class/struct names: solution
Java program:
public class Main { static int N = 100002 ; static int tree [ ] = new int [ 4 * N ] ; static void build ( int arr [ ] , int node , int start , int end ) { if ( start == end ) { tree [ node ] = arr [ start ] ; return ; } int mid = ( start + end ) >> 1 ; build ( arr , 2 * node , start , mid ) ; build ( arr , 2 * node + 1 , mid + 1 , end ) ; tree [ node ] = tree [ 2 * node ] | tree [ 2 * node + 1 ] ; } static int query ( int node , int start , int end , int l , int r ) { if ( start > end start > r end < l ) { return 0 ; } if ( start >= l && end <= r ) { return tree [ node ] ; } int mid = ( start + end ) >> 1 ; int q1 = query ( 2 * node , start , mid , l , r ) ; int q2 = query ( 2 * node + 1 , mid + 1 , end , l , r ) ; return q1 | q2 ; } static int countSubArrays ( int arr [ ] , int n , int K ) { build ( arr , 1 , 0 , n - 1 ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { int bitwise_or = query ( 1 , 0 , n - 1 , i , j ) ; if ( bitwise_or >= K ) count ++ ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 5 } ; int n = arr . length ; int k = 6 ; System . out . print ( countSubArrays ( arr , n , k ) ) ; } }

Index/key variables: node, start
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
class GFG { static int N = 100002 ; static int tree [ ] = new int [ 4 * N ] ; static void build ( int [ ] arr , int node , int start , int end ) { if ( start == end ) { tree [ node ] = arr [ start ] ; return ; } int mid = ( start + end ) >> 1 ; build ( arr , 2 * node , start , mid ) ; build ( arr , 2 * node + 1 , mid + 1 , end ) ; tree [ node ] = tree [ 2 * node ] | tree [ 2 * node + 1 ] ; } static int query ( int node , int start , int end , int l , int r ) { if ( start > end start > r end < l ) { return 0 ; } if ( start >= l && end <= r ) { return tree [ node ] ; } int mid = ( start + end ) >> 1 ; int q1 = query ( 2 * node , start , mid , l , r ) ; int q2 = query ( 2 * node + 1 , mid + 1 , end , l , r ) ; return q1 | q2 ; } static int countSubArrays ( int [ ] arr , int n , int K ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int low = i , high = n - 1 , index = Integer . MAX_VALUE ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( query ( 1 , 0 , n - 1 , i , mid ) >= K ) { index = Math . min ( index , mid ) ; high = mid - 1 ; } else { low = mid + 1 ; } } if ( index != Integer . MAX_VALUE ) { count += n - index ; } } return count ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 5 } ; int n = arr . length ; build ( arr , 1 , 0 , n - 1 ) ; int k = 6 ; System . out . println ( countSubArrays ( arr , n , k ) ) ; } }

Index/key variables: node, start
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class solution { static int countPattern ( int n , String pat ) { int pattern_int = 0 ; int power_two = 1 ; int all_ones = 0 ; for ( int i = pat . length ( ) - 1 ; i >= 0 ; i -- ) { int current_bit = pat . charAt ( i ) - '0' ; pattern_int += ( power_two * current_bit ) ; all_ones = all_ones + power_two ; power_two = power_two * 2 ; } int count = 0 ; while ( n != 0 && n >= pattern_int ) { if ( ( n & all_ones ) == pattern_int ) { count ++ ; } n = n >> 1 ; } return count ; } public static void main ( String args [ ] ) { int n = 500 ; String pat = "10" ; System . out . println ( countPattern ( n , pat ) ) ; } }

Accumulator variables: count, i, pattern_int
Iterator variables: i
Class/struct names: solution
Java program:
import java . util . * ; class GFG { static int max_min ( int a [ ] , int n ) { Arrays . sort ( a ) ; return Math . min ( a [ n - 2 ] - a [ 0 ] , a [ n - 1 ] - a [ 1 ] ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 3 , 7 } ; int n = a . length ; System . out . println ( max_min ( a , n ) ) ; } }

Class/struct names: GFG
Java program:
public class GFG { static final int MAX = 1000001 ; static int primeUpto [ ] = new int [ MAX ] ; static void SieveOfEratosthenes ( ) { int isPrime [ ] = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) isPrime [ i ] = 1 ; isPrime [ 0 ] = isPrime [ 1 ] = 0 ; for ( int i = 2 ; i * i < MAX ; i ++ ) { if ( isPrime [ i ] == 1 ) { for ( int j = i * 2 ; j < MAX ; j += i ) isPrime [ j ] = 0 ; } } for ( int i = 1 ; i < MAX ; i ++ ) { primeUpto [ i ] = primeUpto [ i - 1 ] ; if ( isPrime [ i ] == 1 ) primeUpto [ i ] ++ ; } } static int countOfNumbers ( int N , int K ) { SieveOfEratosthenes ( ) ; int low = 1 , high = N , ans = 0 ; while ( low <= high ) { int mid = ( low + high ) >> 1 ; if ( mid - primeUpto [ mid ] >= K ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } ans = ans != 0 ? N - ans + 1 : 0 ; return ans ; } public static void main ( String [ ] args ) { int N = 10 , K = 3 ; System . out . println ( countOfNumbers ( N , K ) ) ; } }

Index/key variables: MAX, i, j, mid
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int minIndex ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( 2 * arr [ i ] == sum ) return ( i + 1 ) ; } return - 1 ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , - 5 , 3 , 4 } ; int n = arr . length ; System . out . print ( minIndex ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static void printPrevGreater ( int arr [ ] , int n ) { if ( n == 1 ) { System . out . println ( " - 1" ) ; return ; } int v [ ] = Arrays . copyOf ( arr , arr . length ) ; Arrays . sort ( v ) ; for ( int i = 0 ; i < n ; i ++ ) { int it = Arrays . binarySearch ( v , arr [ i ] ) ; it ++ ; if ( ( it - 1 ) != 0 && v [ it - 2 ] == arr [ i ] ) { System . out . print ( arr [ i ] + " ▁ " ) ; } else if ( it != v . length ) System . out . print ( v [ it ] + " ▁ " ) ; else System . out . print ( - 1 + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 5 , 11 , 10 , 20 , 12 } ; int n = arr . length ; printPrevGreater ( arr , n ) ; } }

Index/key variables: i, it
Accumulator variables: i, it
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 = 0 ; i < n ; i ++ ) { if ( mat [ i ] [ i ] < principalMin ) { principalMin = mat [ i ] [ i ] ; } if ( mat [ i ] [ i ] > principalMax ) { principalMax = mat [ i ] [ i ] ; } if ( mat [ n - 1 - i ] [ i ] < secondaryMin ) { secondaryMin = mat [ n - 1 - i ] [ i ] ; } if ( mat [ n - 1 - i ] [ i ] > secondaryMax ) { secondaryMax = mat [ n - 1 - i ] [ i ] ; } } 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
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static boolean checkSorted ( int n , int arr [ ] ) { int first = 0 , second = 0 ; int count = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { count ++ ; if ( first == 0 ) first = i ; else second = i ; } } if ( count > 2 ) return false ; if ( count == 0 ) return true ; if ( count == 2 ) swap ( arr , first - 1 , second ) ; else if ( count == 1 ) swap ( arr , first - 1 , first ) ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] < arr [ i - 1 ] ) return false ; return true ; } static int [ ] swap ( int [ ] arr , int i , int j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 3 , 2 } ; int n = arr . length ; if ( checkSorted ( n , arr ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, j
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int N = 4 ; static int M = 4 ; static void printIntersection ( int A [ ] [ ] , int B [ ] [ ] ) { for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( A [ i ] [ j ] == B [ i ] [ j ] ) System . out . print ( A [ i ] [ j ] + " ▁ " ) ; else System . out . print ( " * ▁ " ) ; } System . out . println ( " ▁ " ) ; } } public static void main ( String [ ] args ) { int A [ ] [ ] = { { 2 , 4 , 6 , 8 } , { 1 , 3 , 5 , 7 } , { 8 , 6 , 4 , 2 } , { 7 , 5 , 3 , 1 } } ; int B [ ] [ ] = { { 2 , 3 , 6 , 8 } , { 1 , 3 , 5 , 2 } , { 8 , 1 , 4 , 2 } , { 3 , 5 , 4 , 1 } } ; printIntersection ( A , B ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int countWays ( int [ ] arr , int n ) { int max_val = 0 ; for ( int i = 0 ; i < n ; i ++ ) max_val = Math . max ( max_val , arr [ i ] ) ; int [ ] freq = new int [ max_val + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ arr [ i ] ] ++ ; ans += freq [ 0 ] * ( freq [ 0 ] - 1 ) * ( freq [ 0 ] - 2 ) / 6 ; for ( int i = 1 ; i <= max_val ; i ++ ) ans += freq [ 0 ] * freq [ i ] * ( freq [ i ] - 1 ) / 2 ; for ( int i = 1 ; 2 * i <= max_val ; i ++ ) ans += freq [ i ] * ( freq [ i ] - 1 ) / 2 * freq [ 2 * i ] ; for ( int i = 1 ; i <= max_val ; i ++ ) { for ( int j = i + 1 ; i + j <= max_val ; j ++ ) ans += freq [ i ] * freq [ j ] * freq [ i + j ] ; } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; System . out . println ( countWays ( arr , 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 int countPairs ( int A1 [ ] , int A2 [ ] , int n1 , int n2 , int K ) { int res = 0 ; Map < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n1 ; ++ i ) { if ( m . containsKey ( A1 [ i ] ) ) m . put ( A1 [ i ] , m . get ( A1 [ i ] ) + 1 ) ; else m . put ( A1 [ i ] , 1 ) ; } for ( int i = 0 ; i < n2 ; ++ i ) { int temp = K - A2 [ i ] ; if ( m . containsKey ( temp ) && m . get ( temp ) != 0 ) { res ++ ; m . put ( temp , m . get ( A1 [ i ] ) - 1 ) ; } } return res ; } public static void main ( String [ ] args ) { int A1 [ ] = { 1 , 1 , 3 , 4 , 5 , 6 , 6 } ; int A2 [ ] = { 1 , 4 , 4 , 5 , 7 } , K = 10 ; int n1 = A1 . length ; int n2 = A2 . length ; System . out . println ( countPairs ( A1 , A2 , n1 , n2 , K ) ) ; } }

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Class/struct names: GfG
Java program:
import java . util . HashMap ; import java . util . Map ; class GFG { public static int countOrderedPairs ( int [ ] A , int n ) { int orderedPairs = 0 ; HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . get ( A [ i ] ) == null ) m . put ( A [ i ] , 1 ) ; else { int a = m . get ( A [ i ] ) ; m . put ( A [ i ] , ++ a ) ; } } for ( int entry : m . keySet ( ) ) { int X = entry ; int Y = m . get ( entry ) ; for ( int j = 1 ; j <= Y ; j ++ ) { if ( m . get ( j ) >= X ) orderedPairs ++ ; } } return orderedPairs ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 1 , 2 , 2 , 3 } ; int n = A . length ; System . out . print ( countOrderedPairs ( A , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, j, orderedPairs
Iterator variables: entry, i, j
Class/struct names: GFG
Java program:
class GFG { static public int LongestSubarray ( int arr [ ] , int n , int k ) { int count = 1 ; int max_length = 1 ; int prev_mod = arr [ 0 ] % k ; for ( int i = 1 ; i < n ; i ++ ) { int curr_mod = arr [ i ] % k ; if ( curr_mod == prev_mod ) { count ++ ; } else { max_length = Math . max ( max_length , count ) ; count = 1 ; prev_mod = curr_mod ; } } return Math . max ( max_length , count ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 9 , 7 , 18 , 29 , 11 } ; int n = arr . length ; int k = 11 ; System . out . print ( LongestSubarray ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static final int M = 3 ; static final int N = 4 ; static boolean binarySearch1D ( int arr [ ] , int K ) { int low = 0 ; int high = N - 1 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( arr [ mid ] == K ) { return true ; } if ( arr [ mid ] < K ) { low = mid + 1 ; } else { high = mid - 1 ; } } return false ; } static boolean searchMatrix ( int matrix [ ] [ ] , int K ) { int low = 0 ; int high = M - 1 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( K >= matrix [ mid ] [ 0 ] && K <= matrix [ mid ] [ N - 1 ] ) { return binarySearch1D ( matrix [ mid ] , K ) ; } if ( K < matrix [ mid ] [ 0 ] ) { high = mid - 1 ; } else { low = mid + 1 ; } } return false ; } public static void main ( String args [ ] ) { int matrix [ ] [ ] = { { 1 , 3 , 5 , 7 } , { 10 , 11 , 16 , 20 } , { 23 , 30 , 34 , 50 } } ; int K = 3 ; if ( searchMatrix ( matrix , K ) ) { System . out . println ( " Found " ) ; } else { System . out . println ( " Not ▁ found " ) ; } } }

Index/key variables: mid
Class/struct names: GFG
Java program:
class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int divTermCount ( int a , int b , int lcm , int num ) { return num / a + num / b - num / lcm ; } static int findNthTerm ( int a , int b , int n ) { int low = 1 , high = Integer . MAX_VALUE , mid ; int lcm = ( a * b ) / gcd ( a , b ) ; while ( low < high ) { mid = low + ( high - low ) / 2 ; if ( divTermCount ( a , b , lcm , mid ) < n ) low = mid + 1 ; else high = mid ; } return low ; } public static void main ( String [ ] args ) { int a = 2 , b = 5 , n = 10 ; System . out . println ( findNthTerm ( a , b , n ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { public String replacePi ( String input ) { String output = " " ; int size = input . length ( ) ; for ( int i = 0 ; i < size ; ++ i ) { if ( i + 1 < size && input . charAt ( i ) == ' p ' && input . charAt ( i + 1 ) == ' i ' ) { output += "3.14" ; i ++ ; } else { output += input . charAt ( i ) ; } } return output ; } public static void main ( String args [ ] ) { GFG g = new GFG ( ) ; String input = "2 ▁ * ▁ pi ▁ + ▁ 3 ▁ * ▁ pi ▁ = ▁ 5 ▁ * ▁ pi " ; System . out . println ( g . replacePi ( input ) ) ; } }

Accumulator variables: i, output
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class Solution { static int numberOfElements ( int height [ ] , int n ) { int max_so_far = 0 ; int coun = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( height [ i ] > max_so_far ) { max_so_far = height [ i ] ; coun ++ ; } } return coun ; } public static void main ( String args [ ] ) { int n = 6 ; int height [ ] = { 4 , 8 , 2 , 0 , 0 , 5 } ; System . out . println ( numberOfElements ( height , n ) ) ; } }

Index/key variables: i
Accumulator variables: coun, i
Iterator variables: i
Class/struct names: Solution
Java program:
import java . util . * ; class Solution { static final int MAX = 100000 ; static class Node { int data ; Node next ; } static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; ( head_ref ) = new_node ; return head_ref ; } static boolean check_pair_product ( Node head , int prod ) { Vector < Integer > s = new Vector < Integer > ( ) ; Node p = head ; while ( p != null ) { int curr = p . data ; if ( ( prod % curr == 0 ) && ( s . contains ( prod / curr ) ) ) { System . out . print ( curr + " ▁ " + ( prod / curr ) ) ; return true ; } s . add ( p . data ) ; p = p . next ; } return false ; } public static void main ( String args [ ] ) { Node head = null ; head = push ( head , 1 ) ; head = push ( head , 2 ) ; head = push ( head , 1 ) ; head = push ( head , 12 ) ; head = push ( head , 1 ) ; head = push ( head , 18 ) ; head = push ( head , 47 ) ; head = push ( head , 16 ) ; head = push ( head , 12 ) ; head = push ( head , 14 ) ; boolean res = check_pair_product ( head , 24 ) ; if ( res == false ) System . out . println ( " NO ▁ PAIR ▁ EXIST " ) ; } }

Class/struct names: Node, Solution