dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class Test { static boolean printPairs ( int arr [ ] , int n , int k ) { boolean isPairFound = true ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i != j && arr [ i ] % arr [ j ] == k ) { System . out . print ( " ( " + arr [ i ] + " , ▁ " + arr [ j ] + " ) " + " ▁ " ) ; isPairFound = true ; } } } return isPairFound ; } public static void main ( String args [ ] ) { int arr [ ] = { 2 , 3 , 5 , 4 , 7 } ; int k = 3 ; if ( printPairs ( arr , arr . length , k ) == false ) System . out . println ( " No ▁ such ▁ pair ▁ exists " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: isPairFound
Class/struct names: Test
Java program:
import java . util . HashMap ; import java . util . Vector ; class Test { static Vector < Integer > findDivisors ( int n ) { Vector < Integer > v = new Vector < > ( ) ; for ( int i = 1 ; i <= Math . sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) v . add ( i ) ; else { v . add ( i ) ; v . add ( n / i ) ; } } } return v ; } static boolean printPairs ( int arr [ ] , int n , int k ) { HashMap < Integer , Boolean > occ = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) occ . put ( arr [ i ] , true ) ; boolean isPairFound = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( occ . get ( k ) && k < arr [ i ] ) { System . out . print ( " ( " + k + " , ▁ " + arr [ i ] + " ) ▁ " ) ; isPairFound = true ; } if ( arr [ i ] >= k ) { Vector < Integer > v = findDivisors ( arr [ i ] - k ) ; for ( int j = 0 ; j < v . size ( ) ; j ++ ) { if ( arr [ i ] % v . get ( j ) == k && arr [ i ] != v . get ( j ) && occ . get ( v . get ( j ) ) ) { System . out . print ( " ( " + arr [ i ] + " , ▁ " + v . get ( j ) + " ) ▁ " ) ; isPairFound = true ; } } v . clear ( ) ; } } return isPairFound ; } public static void main ( String args [ ] ) { int arr [ ] = { 3 , 1 , 2 , 5 , 4 } ; int k = 2 ; if ( printPairs ( arr , arr . length , k ) == false ) System . out . println ( " No ▁ such ▁ pair ▁ exists " ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: isPairFound
Class/struct names: Test
Java program:
import java . util . * ; class GFG { static class Node { int val ; Node left , right ; } ; static Node newNode ( int item ) { Node temp = new Node ( ) ; temp . val = item ; temp . left = temp . right = null ; return temp ; } static int sum = 0 ; static int rangeSumBST ( Node root , int low , int high ) { if ( root == null ) return 0 ; Queue < Node > q = new LinkedList < Node > ( ) ; q . add ( root ) ; while ( q . isEmpty ( ) == false ) { Node curr = q . peek ( ) ; q . remove ( ) ; if ( curr . val >= low && curr . val <= high ) { sum += curr . val ; } if ( curr . left != null && curr . val > low ) q . add ( curr . left ) ; if ( curr . right != null && curr . val < high ) q . add ( curr . right ) ; } return sum ; } static Node insert ( Node node , int data ) { if ( node == null ) return newNode ( data ) ; if ( data <= node . val ) node . left = insert ( node . left , data ) ; else node . right = insert ( node . right , data ) ; return node ; } public static void main ( String [ ] args ) { Node root = null ; root = insert ( root , 10 ) ; insert ( root , 5 ) ; insert ( root , 15 ) ; insert ( root , 3 ) ; insert ( root , 7 ) ; insert ( root , 18 ) ; int L = 7 , R = 15 ; System . out . print ( rangeSumBST ( root , L , R ) ) ; } }

Accumulator variables: sum
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { public static void convert ( int arr [ ] , int n ) { int temp [ ] = arr . clone ( ) ; Arrays . sort ( temp ) ; HashMap < Integer , Integer > umap = new HashMap < > ( ) ; int val = 0 ; for ( int i = 0 ; i < n ; i ++ ) umap . put ( temp [ i ] , val ++ ) ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = umap . get ( arr [ i ] ) ; } public static void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 20 , 15 , 12 , 11 , 50 } ; int n = arr . length ; System . out . println ( " Given ▁ Array ▁ is ▁ " ) ; printArr ( arr , n ) ; convert ( arr , n ) ; System . out . println ( " Converted Array is "); printArr ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i, val
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int countSubstrings ( String S , String S1 , String S2 ) { int N = S . length ( ) ; int N1 = S1 . length ( ) ; int N2 = S2 . length ( ) ; int count = 0 , totalcount = 0 ; for ( int i = 0 ; i < N ; i ++ ) { String prefix = S . substring ( i , ( i + N1 < N ) ? ( i + N1 ) : N ) ; String suffix = S . substring ( i , ( i + N2 < N ) ? ( i + N2 ) : N ) ; if ( S1 . equals ( prefix ) ) count ++ ; if ( S2 . equals ( suffix ) ) totalcount += count ; } return totalcount ; } static void checkSubstrings ( String S , String S1 , String S2 ) { int x = countSubstrings ( S , S1 , S2 ) ; int y = countSubstrings ( S , S2 , S1 ) ; if ( x == y ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String S = " opencloseopencloseopen " ; String S1 = " open " ; String S2 = " close " ; checkSubstrings ( S , S1 , S2 ) ; } }

Accumulator variables: count, i, totalcount
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static final int ASCII_SIZE = 256 ; static char getMaxOccuringChar ( String str ) { int count [ ] = new int [ ASCII_SIZE ] ; int len = str . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) count [ str . charAt ( i ) ] ++ ; int max = - 1 ; char result = ' ▁ ' ; for ( int i = 0 ; i < len ; i ++ ) { if ( max < count [ str . charAt ( i ) ] ) { max = count [ str . charAt ( i ) ] ; result = str . charAt ( i ) ; } } return result ; } public static void main ( String [ ] args ) { String str = " sample ▁ string " ; System . out . println ( " Max ▁ occurring ▁ character ▁ is ▁ " + getMaxOccuringChar ( str ) ) ; } }

Index/key variables: ASCII_SIZE
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . ArrayList ; import java . util . Arrays ; import java . util . HashMap ; import java . util . Map . Entry ; public class GFG { static final int MAX_CHAR = 26 ; static String getKey ( String str ) { boolean [ ] visited = new boolean [ MAX_CHAR ] ; Arrays . fill ( visited , false ) ; for ( int j = 0 ; j < str . length ( ) ; j ++ ) visited [ str . charAt ( j ) - ' a ' ] = true ; String key = " " ; for ( int j = 0 ; j < MAX_CHAR ; j ++ ) if ( visited [ j ] ) key = key + ( char ) ( ' a ' + j ) ; return key ; } static void wordsWithSameCharSet ( String words [ ] , int n ) { HashMap < String , ArrayList < Integer > > Hash = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String key = getKey ( words [ i ] ) ; if ( Hash . containsKey ( key ) ) { ArrayList < Integer > get_al = Hash . get ( key ) ; get_al . add ( i ) ; Hash . put ( key , get_al ) ; } else { ArrayList < Integer > new_al = new ArrayList < > ( ) ; new_al . add ( i ) ; Hash . put ( key , new_al ) ; } } for ( Entry < String , ArrayList < Integer > > it : Hash . entrySet ( ) ) { ArrayList < Integer > get = it . getValue ( ) ; for ( Integer v : get ) System . out . print ( words [ v ] + " , ▁ " ) ; System . out . println ( ) ; } } public static void main ( String args [ ] ) { String words [ ] = { " may " , " student " , " students " , " dog " , " studentssess " , " god " , " cat " , " act " , " tab " , " bat " , " flow " , " wolf " , " lambs " , " amy " , " yam " , " balms " , " looped " , " poodle " } ; int n = words . length ; wordsWithSameCharSet ( words , n ) ; } }

Index/key variables: MAX_CHAR, i, j, v
Accumulator variables: i, j
Iterator variables: i, it, j, v
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String secMostRepeated ( Vector < String > seq ) { HashMap < String , Integer > occ = new HashMap < String , Integer > ( seq . size ( ) ) { @ Override public Integer get ( Object key ) { return containsKey ( key ) ? super . get ( key ) : 0 ; } } ; for ( int i = 0 ; i < seq . size ( ) ; i ++ ) occ . put ( seq . get ( i ) , occ . get ( seq . get ( i ) ) + 1 ) ; int first_max = Integer . MIN_VALUE , sec_max = Integer . MIN_VALUE ; Iterator < Map . Entry < String , Integer > > itr = occ . entrySet ( ) . iterator ( ) ; while ( itr . hasNext ( ) ) { Map . Entry < String , Integer > entry = itr . next ( ) ; int v = entry . getValue ( ) ; if ( v > first_max ) { sec_max = first_max ; first_max = v ; } else if ( v > sec_max && v != first_max ) sec_max = v ; } itr = occ . entrySet ( ) . iterator ( ) ; while ( itr . hasNext ( ) ) { Map . Entry < String , Integer > entry = itr . next ( ) ; int v = entry . getValue ( ) ; if ( v == sec_max ) return entry . getKey ( ) ; } return null ; } public static void main ( String [ ] args ) { String arr [ ] = { " ccc " , " aaa " , " ccc " , " ddd " , " aaa " , " aaa " } ; List < String > seq = Arrays . asList ( arr ) ; System . out . println ( secMostRepeated ( new Vector < > ( seq ) ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . HashSet ; public class CheckDuplicateValues { public static boolean checkDupUtil ( Node root , HashSet < Integer > s ) { if ( root == null ) return false ; if ( s . contains ( root . data ) ) return true ; s . add ( root . data ) ; return checkDupUtil ( root . left , s ) || checkDupUtil ( root . right , s ) ; } public static boolean checkDup ( Node root ) { HashSet < Integer > s = new HashSet < > ( ) ; return checkDupUtil ( root , s ) ; } public static void main ( String args [ ] ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 2 ) ; root . left . left = new Node ( 3 ) ; if ( checkDup ( root ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } } class Node { int data ; Node left , right ; Node ( int data ) { this . data = data ; } } ;

Class/struct names: CheckDuplicateValues, Node
Java program:
import java . util . Stack ; class Node { char value ; Node left , right ; Node ( char item ) { value = item ; left = right = null ; } } class ExpressionTree { boolean isOperator ( char c ) { if ( c == ' + ' c == ' - ' c == ' * ' c == ' / ' c == ' ^ ' ) { return true ; } return false ; } void inorder ( Node t ) { if ( t != null ) { inorder ( t . left ) ; System . out . print ( t . value + " ▁ " ) ; inorder ( t . right ) ; } } Node constructTree ( char postfix [ ] ) { Stack < Node > st = new Stack < Node > ( ) ; Node t , t1 , t2 ; for ( int i = 0 ; i < postfix . length ; i ++ ) { if ( ! isOperator ( postfix [ i ] ) ) { t = new Node ( postfix [ i ] ) ; st . push ( t ) ; } else { t = new Node ( postfix [ i ] ) ; t1 = st . pop ( ) ; t2 = st . pop ( ) ; t . right = t1 ; t . left = t2 ; st . push ( t ) ; } } t = st . peek ( ) ; st . pop ( ) ; return t ; } public static void main ( String args [ ] ) { ExpressionTree et = new ExpressionTree ( ) ; String postfix = " ab + ef * g * - " ; char [ ] charArray = postfix . toCharArray ( ) ; Node root = et . constructTree ( charArray ) ; System . out . println ( " infix ▁ expression ▁ is " ) ; et . inorder ( root ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: ExpressionTree, Node
Java program:
import java . io . * ; import java . util . * ; class GFG { static void totalCount ( int [ ] [ ] A , int N , int M , int [ ] [ ] queries , int Q ) { int row_sum [ ] = new int [ N ] ; int col_sum [ ] = new int [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { row_sum [ i ] += A [ i ] [ j ] ; col_sum [ j ] += A [ i ] [ j ] ; } } ArrayList < Integer > sum_list = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) sum_list . add ( row_sum [ i ] ) ; for ( int i = 0 ; i < M ; i ++ ) sum_list . add ( col_sum [ i ] ) ; Collections . sort ( sum_list ) ; for ( int i = 0 ; i < Q ; i ++ ) { int L = queries [ i ] [ 0 ] ; int R = queries [ i ] [ 1 ] ; int l = left_search ( sum_list , L ) ; int r = right_search ( sum_list , R ) ; System . out . print ( r - l + 1 + " ▁ " ) ; } } static int left_search ( ArrayList < Integer > A , int num ) { int low = 0 , high = A . size ( ) - 1 ; int ans = 0 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( A . get ( mid ) >= num ) { ans = mid ; high = mid - 1 ; } else { low = mid + 1 ; } } return ans ; } static int right_search ( ArrayList < Integer > A , int num ) { int low = 0 , high = A . size ( ) - 1 ; int ans = high ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( A . get ( mid ) <= num ) { ans = mid ; low = mid + 1 ; } else { high = mid - 1 ; } } return ans ; } public static void main ( String [ ] args ) { int N = 3 , M = 2 ; int A [ ] [ ] = { { 13 , 3 } , { 9 , 4 } , { 6 , 10 } } ; int Q = 2 ; int queries [ ] [ ] = { { 10 , 20 } , { 25 , 35 } } ; totalCount ( A , N , M , queries , Q ) ; } }

Index/key variables: M, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int smallestKFreq ( int a [ ] , int n , int k ) { HashMap < Integer , Integer > m = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( m . containsKey ( a [ i ] ) ) m . put ( a [ i ] , m . get ( a [ i ] ) + 1 ) ; else m . put ( a [ i ] , 1 ) ; int res = Integer . MAX_VALUE ; Set < Integer > s = m . keySet ( ) ; for ( int temp : s ) if ( m . get ( temp ) == k ) res = Math . min ( res , temp ) ; return ( res != Integer . MAX_VALUE ) ? res : - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 2 , 1 , 3 , 1 } ; int k = 2 ; System . out . println ( smallestKFreq ( arr , arr . length , k ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i, temp
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int maximumProfit ( int arr [ ] ) { int ans = Integer . MIN_VALUE ; int price = 0 ; Arrays . sort ( arr ) ; int N = arr . length ; for ( int i = 0 ; i < N ; i ++ ) { int count = ( N - i ) ; if ( ans < count * arr [ i ] ) { price = arr [ i ] ; ans = count * arr [ i ] ; } } return price ; } public static void main ( String [ ] args ) { int arr [ ] = { 22 , 87 , 9 , 50 , 56 , 43 } ; System . out . print ( maximumProfit ( arr ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void print ( int arr [ ] ) { for ( int element : arr ) { System . out . print ( element + " ▁ " ) ; } } static void makeLexicographically ( int arr [ ] , int length ) { int index = 0 ; int temp = 0 ; int check = 0 ; int condition = 0 ; int element = 0 ; for ( int i = 0 ; i < length ; ++ i ) { if ( element == arr [ i ] ) { check = i ; break ; } else if ( arr [ i ] != i + 1 && check == 0 ) { index = i ; check = 1 ; condition = - 1 ; element = i + 1 ; } } if ( condition == - 1 ) { temp = arr [ index ] ; arr [ index ] = arr [ check ] ; arr [ check ] = temp ; } print ( arr ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = arr . length ; makeLexicographically ( arr , N ) ; } }

Index/key variables: check, i, index
Iterator variables: element, i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static boolean isLower ( char c ) { return c >= ' a ' && c <= ' z ' ; } static boolean isUpper ( char c ) { return c >= ' A ' && c <= ' Z ' ; } static boolean detectUppercaseUseUtil ( String S ) { int N = S . length ( ) ; int i ; if ( isLower ( S . charAt ( 0 ) ) ) { i = 1 ; while ( i < N && isLower ( S . charAt ( i ) ) ) ++ i ; return i == N ? true : false ; } else { i = 1 ; while ( i < N && isUpper ( S . charAt ( i ) ) ) ++ i ; if ( i == N ) return true ; else if ( i > 1 ) return false ; while ( i < N && isLower ( S . charAt ( i ) ) ) ++ i ; return i == N ? true : false ; } } static void detectUppercaseUse ( String S ) { boolean check = detectUppercaseUseUtil ( S ) ; if ( check ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String S = " GeeKs " ; detectUppercaseUse ( S ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int check ( int N ) { if ( Integer . bitCount ( N ) == 1 ) return 1 ; else return 0 ; } static void build_seg_tree ( int ss , int se , int si , int tree [ ] , int arr [ ] ) { if ( ss == se ) { tree [ si ] = check ( arr [ ss ] ) ; return ; } int mid = ( ss + se ) / 2 ; build_seg_tree ( ss , mid , 2 * si + 1 , tree , arr ) ; build_seg_tree ( mid + 1 , se , 2 * si + 2 , tree , arr ) ; tree [ si ] = tree [ 2 * si + 1 ] + tree [ 2 * si + 2 ] ; } static void update ( int ss , int se , int si , int X , int V , int tree [ ] , int arr [ ] ) { if ( ss == se ) { if ( ss == X ) { arr [ X ] = V ; tree [ si ] = check ( V ) ; } return ; } int mid = ( ss + se ) / 2 ; if ( X <= mid ) update ( ss , mid , 2 * si + 1 , X , V , tree , arr ) ; else update ( mid + 1 , se , 2 * si + 2 , X , V , tree , arr ) ; tree [ si ] = tree [ 2 * si + 1 ] + tree [ 2 * si + 2 ] ; } static int query ( int l , int r , int ss , int se , int si , int tree [ ] ) { if ( r < ss l > se ) return 0 ; if ( l <= ss && r >= se ) return tree [ si ] ; int mid = ( ss + se ) / 2 ; return query ( l , r , ss , mid , 2 * si + 1 , tree ) + query ( l , r , mid + 1 , se , 2 * si + 2 , tree ) ; } static void Query ( int arr [ ] , int N , int [ ] [ ] Q ) { int tree [ ] = new int [ 4 * N ] ; build_seg_tree ( 0 , N - 1 , 0 , tree , arr ) ; for ( int i = 0 ; i < Q . length ; i ++ ) { if ( Q [ i ] [ 0 ] == 1 ) System . out . print ( query ( Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , 0 , N - 1 , 0 , tree ) + " ▁ " ) ; else update ( 0 , N - 1 , 0 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , tree , arr ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 11 , 16 , 2 , 32 } ; int [ ] [ ] Q = { { 1 , 0 , 2 } , { 2 , 4 , 24 } , { 1 , 1 , 4 } } ; int N = arr . length ; Query ( arr , N , Q ) ; } }

Index/key variables: X, i, si, ss
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isGreaterEqual ( int N , int X ) { return ( N * ( N + 1 ) / 2 ) >= X ; } static int minimumPossible ( int X ) { int low = 1 , high = X , res = - 1 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( isGreaterEqual ( mid , X ) ) { res = mid ; high = mid - 1 ; } else low = mid + 1 ; } return res ; } public static void main ( String [ ] args ) { int X = 14 ; System . out . print ( minimumPossible ( X ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static class pair { int x , y ; pair ( int x , int y ) { this . x = x ; this . y = y ; } } static int m , n ; static int minStep ( int [ ] [ ] mat ) { m = mat . length ; n = mat [ 0 ] . length ; int dx [ ] = { 1 , - 1 , 0 , 0 } ; int dy [ ] = { 0 , 0 , 1 , - 1 } ; Queue < pair > pQ = new LinkedList < > ( ) ; Queue < pair > fQ = new LinkedList < > ( ) ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) { if ( mat [ i ] [ j ] == 2 ) fQ . add ( new pair ( i , j ) ) ; else if ( mat [ i ] [ j ] == 1 ) { if ( border ( i , j ) ) return 0 ; pQ . add ( new pair ( i , j ) ) ; } } int depth = 0 ; boolean [ ] [ ] visited = new boolean [ n ] [ m ] ; while ( ! pQ . isEmpty ( ) ) { depth ++ ; for ( int i = pQ . size ( ) ; i > 0 ; i -- ) { pair pos = pQ . peek ( ) ; pQ . remove ( ) ; if ( mat [ pos . x ] [ pos . y ] == 2 ) continue ; for ( int j = 0 ; j < 4 ; j ++ ) { int x = pos . x + dx [ j ] ; int y = pos . y + dy [ j ] ; if ( valid ( x , y ) && mat [ x ] [ y ] != 2 && ! visited [ x ] [ y ] ) { visited [ x ] [ y ] = true ; pQ . add ( new pair ( x , y ) ) ; if ( border ( x , y ) ) return depth ; } } } for ( int i = fQ . size ( ) ; i > 0 ; i -- ) { pair pos = fQ . peek ( ) ; fQ . remove ( ) ; for ( int j = 0 ; j < 4 ; j ++ ) { int x = pos . x + dx [ j ] ; int y = pos . y + dy [ j ] ; if ( valid ( x , y ) && mat [ x ] [ y ] != 2 ) { mat [ x ] [ y ] = 2 ; fQ . add ( new pair ( x , y ) ) ; } } } } return - 1 ; } static boolean valid ( int x , int y ) { return ( x >= 0 && x < m && y >= 0 && y < n ) ; } static boolean border ( int x , int y ) { return ( x == 0 x == m - 1 y == 0 y == n - 1 ) ; } public static void main ( String [ ] args ) { int [ ] [ ] grid = { { 0 , 0 , 0 , 0 } , { 2 , 0 , 0 , 0 } , { 2 , 1 , 0 , 0 } , { 2 , 2 , 0 , 0 } } ; System . out . println ( minStep ( grid ) ) ; } }

Index/key variables: i, j, m, n, x, y
Accumulator variables: depth, i, j
Iterator variables: i, j
Class/struct names: GFG, pair
Java program:
import java . util . Arrays ; public class GFG { static int findSum ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int sum = arr [ 0 ] ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] != arr [ i + 1 ] ) { sum = sum + arr [ i + 1 ] ; } } return sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 } ; int n = arr . length ; System . out . println ( findSum ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int xorSubsequence ( int a [ ] , int n , int k ) { int ans = 0 ; int dp [ ] = new int [ n ] ; dp [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = i - 1 ; j >= 0 ; j -- ) { if ( ( a [ i ] ^ a [ j ] ) == k ) dp [ i ] = Math . max ( dp [ i ] , dp [ j ] + 1 ) ; } ans = Math . max ( ans , dp [ i ] ) ; dp [ i ] = Math . max ( 1 , dp [ i ] ) ; } return ans >= 2 ? ans : 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 4 , 3 , 5 } ; int K = 1 ; int N = arr . length ; System . out . println ( xorSubsequence ( arr , N , K ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . HashSet ; public class Main { static char MARKER = ' $ ' ; class Node { int data ; Node left , right ; Node ( int data ) { this . data = data ; } } ; public static String dupSubUtil ( Node root , HashSet < String > subtrees ) { String s = " " ; if ( root == null ) return s + MARKER ; String lStr = dupSubUtil ( root . left , subtrees ) ; if ( lStr . equals ( s ) ) return s ; String rStr = dupSubUtil ( root . right , subtrees ) ; if ( rStr . equals ( s ) ) return s ; s = s + root . data + lStr + rStr ; if ( s . length ( ) > 3 && subtrees . contains ( s ) ) return " " ; subtrees . add ( s ) ; return s ; } public static String dupSub ( Node root ) { HashSet < String > subtrees = new HashSet < > ( ) ; return dupSubUtil ( root , subtrees ) ; } public static void main ( String args [ ] ) { Node root = new Node ( ' A ' ) ; root . left = new Node ( ' B ' ) ; root . right = new Node ( ' C ' ) ; root . left . left = new Node ( ' D ' ) ; root . left . right = new Node ( ' E ' ) ; root . right . right = new Node ( ' B ' ) ; root . right . right . right = new Node ( ' E ' ) ; root . right . right . left = new Node ( ' D ' ) ; String str = dupSub ( root ) ; if ( str . equals ( " " ) ) System . out . print ( " ▁ Yes ▁ " ) ; else System . out . print ( " ▁ No ▁ " ) ; } }

Class/struct names: Main, Node
Java program:
import java . util . * ; class GFG { public static int getCount ( int rows , int columns , int [ ] [ ] sides ) { int res = 0 ; Map < Double , Integer > ratio = new HashMap < Double , Integer > ( ) ; for ( int i = 0 ; i < rows ; i ++ ) { double rectRatio = ( double ) sides [ i ] [ 0 ] / sides [ i ] [ 1 ] ; if ( ratio . get ( rectRatio ) == null ) { ratio . put ( rectRatio , 0 ) ; } ratio . put ( rectRatio , ratio . get ( rectRatio ) + 1 ) ; } for ( double key : ratio . keySet ( ) ) { int val = ratio . get ( key ) ; if ( val > 1 ) { res += ( val * ( val - 1 ) ) / 2 ; } } return res ; } public static void main ( String [ ] args ) { int [ ] [ ] A = { { 4 , 8 } , { 10 , 20 } , { 15 , 30 } , { 3 , 6 } } ; int columns = 2 ; int rows = 4 ; System . out . println ( getCount ( rows , columns , A ) ) ; } }

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i, key
Class/struct names: GFG