dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . HashMap ; import java . util . Map ; import java . util . Map . Entry ; class GFG { static int mostFrequent ( int arr [ ] , int n ) { Map < Integer , Integer > hp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int key = arr [ i ] ; if ( hp . containsKey ( key ) ) { int freq = hp . get ( key ) ; freq ++ ; hp . put ( key , freq ) ; } else { hp . put ( key , 1 ) ; } } int max_count = 0 , res = - 1 ; for ( Entry < Integer , Integer > val : hp . entrySet ( ) ) { if ( max_count < val . getValue ( ) ) { res = val . getKey ( ) ; max_count = val . getValue ( ) ; } } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 2 , 1 , 3 , 2 , 1 } ; int n = arr . length ; System . out . println ( mostFrequent ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: freq, i
Iterator variables: i, val
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GfG { static void smallestSubsegment ( int a [ ] , int n ) { HashMap < Integer , Integer > left = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ; int mx = 0 ; int mn = - 1 , strindex = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int x = a [ i ] ; if ( count . get ( x ) == null ) { left . put ( x , i ) ; count . put ( x , 1 ) ; } else count . put ( x , count . get ( x ) + 1 ) ; if ( count . get ( x ) > mx ) { mx = count . get ( x ) ; mn = i - left . get ( x ) + 1 ; strindex = left . get ( x ) ; } else if ( ( count . get ( x ) == mx ) && ( i - left . get ( x ) + 1 < mn ) ) { mn = i - left . get ( x ) + 1 ; strindex = left . get ( x ) ; } } for ( int i = strindex ; i < strindex + mn ; i ++ ) System . out . print ( a [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 2 , 2 , 1 } ; int n = A . length ; smallestSubsegment ( A , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GfG
Java program:
import java . util . HashMap ; class SymmetricPairs { static void findSymPairs ( int arr [ ] [ ] ) { HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { int first = arr [ i ] [ 0 ] ; int sec = arr [ i ] [ 1 ] ; Integer val = hM . get ( sec ) ; if ( val != null && val == first ) System . out . println ( " ( " + sec + " , ▁ " + first + " ) " ) ; else hM . put ( first , sec ) ; } } public static void main ( String arg [ ] ) { int arr [ ] [ ] = new int [ 5 ] [ 2 ] ; arr [ 0 ] [ 0 ] = 11 ; arr [ 0 ] [ 1 ] = 20 ; arr [ 1 ] [ 0 ] = 30 ; arr [ 1 ] [ 1 ] = 40 ; arr [ 2 ] [ 0 ] = 5 ; arr [ 2 ] [ 1 ] = 10 ; arr [ 3 ] [ 0 ] = 40 ; arr [ 3 ] [ 1 ] = 30 ; arr [ 4 ] [ 0 ] = 10 ; arr [ 4 ] [ 1 ] = 5 ; findSymPairs ( arr ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: SymmetricPairs
Java program:
import java . io . * ; import java . util . * ; class GFG { static int findRepeatingNumber ( int [ ] arr , int n ) { int sq = ( int ) Math . sqrt ( n ) ; int range = ( n / sq ) + 1 ; int [ ] count = new int [ range ] ; for ( int i = 0 ; i <= n ; i ++ ) { count [ ( arr [ i ] - 1 ) / sq ] ++ ; } int selected_block = range - 1 ; for ( int i = 0 ; i < range - 1 ; i ++ ) { if ( count [ i ] > sq ) { selected_block = i ; break ; } } HashMap < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i <= n ; i ++ ) { if ( ( ( selected_block * sq ) < arr [ i ] ) && ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) { m . put ( arr [ i ] , 1 ) ; if ( m . get ( arr [ i ] ) == 1 ) return arr [ i ] ; } } return - 1 ; } public static void main ( String args [ ] ) { int [ ] arr = { 1 , 1 , 2 , 3 , 5 , 4 } ; int n = 5 ; System . out . println ( " One ▁ of ▁ the ▁ numbers ▁ repeated ▁ in ▁ the ▁ array ▁ is : ▁ " + findRepeatingNumber ( arr , n ) ) ; } }

Index/key variables: i, range
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class Pair { int first , second ; } class GFG { static void top3Repeated ( int [ ] arr , int n ) { if ( n < 3 ) { System . out . print ( " Invalid ▁ Input " ) ; return ; } TreeMap < Integer , Integer > freq = new TreeMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( freq . containsKey ( arr [ i ] ) ) freq . put ( arr [ i ] , 1 + freq . get ( arr [ i ] ) ) ; else freq . put ( arr [ i ] , 1 ) ; Pair x = new Pair ( ) ; Pair y = new Pair ( ) ; Pair z = new Pair ( ) ; x . first = y . first = z . first = Integer . MIN_VALUE ; for ( Map . Entry curr : freq . entrySet ( ) ) { if ( Integer . parseInt ( String . valueOf ( curr . getValue ( ) ) ) > x . first ) { z . first = y . first ; z . second = y . second ; y . first = x . first ; y . second = x . second ; x . first = Integer . parseInt ( String . valueOf ( curr . getValue ( ) ) ) ; x . second = Integer . parseInt ( String . valueOf ( curr . getKey ( ) ) ) ; } else if ( Integer . parseInt ( String . valueOf ( curr . getValue ( ) ) ) > y . first ) { z . first = y . first ; z . second = y . second ; y . first = Integer . parseInt ( String . valueOf ( curr . getValue ( ) ) ) ; y . second = Integer . parseInt ( String . valueOf ( curr . getKey ( ) ) ) ; } else if ( Integer . parseInt ( String . valueOf ( curr . getValue ( ) ) ) > z . first ) { z . first = Integer . parseInt ( String . valueOf ( curr . getValue ( ) ) ) ; z . second = Integer . parseInt ( String . valueOf ( curr . getKey ( ) ) ) ; } } System . out . print ( " Three ▁ largest ▁ elements ▁ are ▁ " + x . second + " ▁ " + y . second + " ▁ " + z . second ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 3 , 4 , 2 , 3 , 16 , 3 , 15 , 16 , 15 , 15 , 16 , 2 , 3 } ; int n = arr . length ; top3Repeated ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Pair
Java program:
class GFG { static void groupElements ( int arr [ ] , int n ) { boolean visited [ ] = new boolean [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { visited [ i ] = false ; } for ( int i = 0 ; i < n ; i ++ ) { if ( ! visited [ i ] ) { System . out . print ( arr [ i ] + " ▁ " ) ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] == arr [ j ] ) { System . out . print ( arr [ i ] + " ▁ " ) ; visited [ j ] = true ; } } } } } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 6 , 9 , 2 , 3 , 4 , 9 , 6 , 10 , 4 } ; int n = arr . length ; groupElements ( arr , n ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . HashMap ; class Main { static void orderedGroup ( int arr [ ] ) { HashMap < Integer , Integer > hM = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { Integer prevCount = hM . get ( arr [ i ] ) ; if ( prevCount == null ) prevCount = 0 ; hM . put ( arr [ i ] , prevCount + 1 ) ; } for ( int i = 0 ; i < arr . length ; i ++ ) { Integer count = hM . get ( arr [ i ] ) ; if ( count != null ) { for ( int j = 0 ; j < count ; j ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; hM . remove ( arr [ i ] ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 5 , 3 , 10 , 10 , 4 , 1 , 3 } ; orderedGroup ( arr ) ; } }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
public class disjoint1 { boolean aredisjoint ( int set1 [ ] , int set2 [ ] ) { for ( int i = 0 ; i < set1 . length ; i ++ ) { for ( int j = 0 ; j < set2 . length ; j ++ ) { if ( set1 [ i ] == set2 [ j ] ) return false ; } } return true ; } public static void main ( String [ ] args ) { disjoint1 dis = new disjoint1 ( ) ; int set1 [ ] = { 12 , 34 , 11 , 9 , 3 } ; int set2 [ ] = { 7 , 2 , 1 , 5 } ; boolean result = dis . aredisjoint ( set1 , set2 ) ; if ( result ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: disjoint1
Java program:
import java . util . Arrays ; public class disjoint1 { boolean aredisjoint ( int set1 [ ] , int set2 [ ] ) { int i = 0 , j = 0 ; Arrays . sort ( set1 ) ; Arrays . sort ( set2 ) ; while ( i < set1 . length && j < set2 . length ) { if ( set1 [ i ] < set2 [ j ] ) i ++ ; else if ( set1 [ i ] > set2 [ j ] ) j ++ ; else return false ; } return true ; } public static void main ( String [ ] args ) { disjoint1 dis = new disjoint1 ( ) ; int set1 [ ] = { 12 , 34 , 11 , 9 , 3 } ; int set2 [ ] = { 7 , 2 , 1 , 5 } ; boolean result = dis . aredisjoint ( set1 , set2 ) ; if ( result ) System . out . println ( " YES " ) ; else System . out . println ( " NO " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Class/struct names: disjoint1
Java program:
import java . util . * ; class Main { static boolean areDisjoint ( int set1 [ ] , int set2 [ ] ) { HashSet < Integer > set = new HashSet < > ( ) ; for ( int i = 0 ; i < set1 . length ; i ++ ) set . add ( set1 [ i ] ) ; for ( int i = 0 ; i < set2 . length ; i ++ ) if ( set . contains ( set2 [ i ] ) ) return false ; return true ; } public static void main ( String [ ] args ) { int set1 [ ] = { 10 , 5 , 3 , 4 , 6 } ; int set2 [ ] = { 8 , 7 , 9 , 3 } ; if ( areDisjoint ( set1 , set2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Main
Java program:
import java . io . * ; import java . util . * ; class GFG { static int findSum ( int [ ] A , int [ ] B , int n ) { HashMap < Integer , Integer > hash = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( hash . containsKey ( A [ i ] ) ) hash . put ( A [ i ] , 1 + hash . get ( A [ i ] ) ) ; else hash . put ( A [ i ] , 1 ) ; if ( hash . containsKey ( B [ i ] ) ) hash . put ( B [ i ] , 1 + hash . get ( B [ i ] ) ) ; else hash . put ( B [ i ] , 1 ) ; } int sum = 0 ; for ( Map . Entry entry : hash . entrySet ( ) ) { if ( Integer . parseInt ( ( entry . getValue ( ) ) . toString ( ) ) == 1 ) sum += Integer . parseInt ( ( entry . getKey ( ) ) . toString ( ) ) ; } return sum ; } public static void main ( String args [ ] ) { int [ ] A = { 5 , 4 , 9 , 2 , 3 } ; int [ ] B = { 2 , 8 , 7 , 6 , 3 } ; int n = A . length ; System . out . println ( findSum ( A , B , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void findMissing ( int a [ ] , int b [ ] , int n , int m ) { for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = 0 ; j < m ; j ++ ) if ( a [ i ] == b [ j ] ) break ; if ( j == m ) System . out . print ( a [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 6 , 3 , 4 , 5 } ; int b [ ] = { 2 , 4 , 3 , 1 , 0 } ; int n = a . length ; int m = b . length ; findMissing ( a , b , n , m ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . HashSet ; import java . util . Set ; public class GfG { static void findMissing ( int a [ ] , int b [ ] , int n , int m ) { HashSet < Integer > s = new HashSet < > ( ) ; for ( int i = 0 ; i < m ; i ++ ) s . add ( b [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) if ( ! s . contains ( a [ i ] ) ) System . out . print ( a [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 6 , 3 , 4 , 5 } ; int b [ ] = { 2 , 4 , 3 , 1 , 0 } ; int n = a . length ; int m = b . length ; findMissing ( a , b , n , m ) ; } }

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 boolean areEqual ( int arr1 [ ] , int arr2 [ ] ) { int n = arr1 . length ; int m = arr2 . length ; if ( n != m ) return false ; Arrays . sort ( arr1 ) ; Arrays . sort ( arr2 ) ; for ( int i = 0 ; i < n ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return false ; return true ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 3 , 5 , 2 , 5 , 2 } ; int arr2 [ ] = { 2 , 3 , 5 , 5 , 2 } ; if ( areEqual ( arr1 , arr2 ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void makePermutation ( int [ ] a , int n ) { HashMap < Integer , Integer > count = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( count . containsKey ( a [ i ] ) ) { count . put ( a [ i ] , count . get ( a [ i ] ) + 1 ) ; } else { count . put ( a [ i ] , 1 ) ; } } } static int find_maximum ( int a [ ] , int n , int k ) { HashMap < Integer , Integer > b = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int x = a [ i ] ; int d = Math . min ( 1 + i , n - i ) ; if ( ! b . containsKey ( x ) ) b . put ( x , d ) ; else { b . put ( x , Math . min ( d , b . get ( x ) ) ) ; } } int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int x = a [ i ] ; if ( x != k - x && b . containsKey ( k - x ) ) ans = Math . min ( Math . max ( b . get ( x ) , b . get ( k - x ) ) , ans ) ; } return ans ; } public static void main ( String [ ] args ) { int a [ ] = { 3 , 5 , 8 , 6 , 7 } ; int K = 11 ; int n = a . length ; System . out . println ( find_maximum ( a , n , K ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { boolean isProduct ( int arr [ ] , int n , int x ) { for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] * arr [ j ] == x ) return true ; return false ; } public static void main ( String [ ] args ) { GFG g = new GFG ( ) ; int arr [ ] = { 10 , 20 , 9 , 40 } ; int x = 400 ; int n = arr . length ; if ( g . isProduct ( arr , n , x ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; x = 190 ; if ( g . isProduct ( arr , n , x ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . HashSet ; class GFG { static boolean isProduct ( int arr [ ] , int n , int x ) { HashSet < Integer > hset = new HashSet < > ( ) ; if ( n < 2 ) return false ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) { if ( x == 0 ) return true ; else continue ; } if ( x % arr [ i ] == 0 ) { if ( hset . contains ( x / arr [ i ] ) ) return true ; hset . add ( arr [ i ] ) ; } } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 20 , 9 , 40 } ; int x = 400 ; int n = arr . length ; if ( isProduct ( arr , arr . length , x ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; x = 190 ; if ( isProduct ( arr , arr . length , x ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int findGreatest ( int [ ] arr , int n ) { int result = - 1 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n - 1 ; j ++ ) for ( int k = j + 1 ; k < n ; k ++ ) if ( arr [ j ] * arr [ k ] == arr [ i ] ) result = Math . max ( result , arr [ i ] ) ; return result ; } static public void main ( String [ ] args ) { int [ ] arr = { 30 , 10 , 9 , 3 , 35 } ; int n = arr . length ; System . out . println ( findGreatest ( arr , n ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findGreatest ( int arr [ ] , int n ) { Map < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( m . containsKey ( arr [ i ] ) ) { m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; } else { m . put ( arr [ i ] , m . get ( arr [ i ] ) ) ; } } Arrays . sort ( arr ) ; for ( int i = n - 1 ; i > 1 ; i -- ) { for ( int j = 0 ; j < i && arr [ j ] <= Math . sqrt ( arr [ i ] ) ; j ++ ) { if ( arr [ i ] % arr [ j ] == 0 ) { int result = arr [ i ] / arr [ j ] ; if ( result != arr [ j ] && m . get ( result ) == null || m . get ( result ) > 0 ) { return arr [ i ] ; } else if ( result == arr [ j ] && m . get ( result ) > 1 ) { return arr [ i ] ; } } } } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 17 , 2 , 1 , 15 , 30 } ; int n = arr . length ; System . out . println ( findGreatest ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int minRemove ( int a [ ] , int b [ ] , int n , int m ) { HashMap < Integer , Integer > countA = new HashMap < Integer , Integer > ( ) ; HashMap < Integer , Integer > countB = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( countA . containsKey ( a [ i ] ) ) countA . put ( a [ i ] , countA . get ( a [ i ] ) + 1 ) ; else countA . put ( a [ i ] , 1 ) ; } for ( int i = 0 ; i < m ; i ++ ) { if ( countB . containsKey ( b [ i ] ) ) countB . put ( b [ i ] , countB . get ( b [ i ] ) + 1 ) ; else countB . put ( b [ i ] , 1 ) ; } int res = 0 ; Set < Integer > s = countA . keySet ( ) ; for ( int x : s ) if ( countB . containsKey ( x ) ) res += Math . min ( countB . get ( x ) , countA . get ( x ) ) ; return res ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 3 , 4 } ; int b [ ] = { 2 , 3 , 4 , 5 , 8 } ; int n = a . length ; int m = b . length ; System . out . println ( minRemove ( a , b , n , m ) ) ; } }

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i, x
Class/struct names: GFG
Java program:
class GFG { static class item { String name ; int price ; public item ( String name , int price ) { this . name = name ; this . price = price ; } } ; static int countItems ( item list1 [ ] , int m , item list2 [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( ( list1 [ i ] . name . compareTo ( list2 [ j ] . name ) == 0 ) && ( list1 [ i ] . price != list2 [ j ] . price ) ) count ++ ; return count ; } public static void main ( String [ ] args ) { item list1 [ ] = { new item ( " apple " , 60 ) , new item ( " bread " , 20 ) , new item ( " wheat " , 50 ) , new item ( " oil " , 30 ) } ; item list2 [ ] = { new item ( " milk " , 20 ) , new item ( " bread " , 15 ) , new item ( " wheat " , 40 ) , new item ( " apple " , 60 ) } ; int m = list1 . length ; int n = list2 . length ; System . out . print ( " Count ▁ = ▁ " + countItems ( list1 , m , list2 , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG, item
Java program:
import java . util . * ; class GFG { static class item { String name ; int price ; item ( String name , int price ) { this . name = name ; this . price = price ; } } ; static class Com implements Comparator < item > { public int compare ( item a , item b ) { return a . name . compareTo ( b . name ) ; } } static int binary_search ( item list2 [ ] , int low , int high , String str ) { while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( list2 [ mid ] . name . compareTo ( str ) == 0 ) return list2 [ mid ] . price ; else if ( list2 [ mid ] . name . compareTo ( str ) < 0 ) low = mid + 1 ; else high = mid - 1 ; } return - 1 ; } static int countItems ( item list1 [ ] , int m , item list2 [ ] , int n ) { Arrays . sort ( list2 , new Com ( ) ) ; int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) { int r = binary_search ( list2 , 0 , n - 1 , list1 [ i ] . name ) ; if ( ( r != - 1 ) && ( r != list1 [ i ] . price ) ) count ++ ; } return count ; } public static void main ( String [ ] args ) { item [ ] list1 = { new item ( " apple " , 60 ) , new item ( " bread " , 20 ) , new item ( " wheat " , 50 ) , new item ( " oil " , 30 ) } ; item list2 [ ] = { new item ( " milk " , 20 ) , new item ( " bread " , 15 ) , new item ( " wheat " , 40 ) , new item ( " apple " , 60 ) } ; int m = list1 . length ; int n = list2 . length ; System . out . print ( " Count ▁ = ▁ " + countItems ( list1 , m , list2 , n ) ) ; } }

Index/key variables: i, mid
Accumulator variables: count, i
Iterator variables: i
Class/struct names: Com, GFG, item
Java program:
import java . util . * ; class GFG { static class item { String name ; int price ; public item ( String name , int price ) { this . name = name ; this . price = price ; } } ; static int countItems ( item list1 [ ] , int m , item list2 [ ] , int n ) { HashMap < String , Integer > um = new HashMap < > ( ) ; int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) um . put ( list1 [ i ] . name , list1 [ i ] . price ) ; for ( int i = 0 ; i < n ; i ++ ) if ( ( um . containsKey ( list2 [ i ] . name ) ) && ( um . get ( list2 [ i ] . name ) != list2 [ i ] . price ) ) count ++ ; return count ; } public static void main ( String [ ] args ) { item list1 [ ] = { new item ( " apple " , 60 ) , new item ( " bread " , 20 ) , new item ( " wheat " , 50 ) , new item ( " oil " , 30 ) } ; item list2 [ ] = { new item ( " milk " , 20 ) , new item ( " bread " , 15 ) , new item ( " wheat " , 40 ) , new item ( " apple " , 60 ) } ; int m = list1 . length ; int n = list2 . length ; System . out . print ( " Count ▁ = ▁ " + countItems ( list1 , m , clist2 , n ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG, item
Java program:
import java . util . * ; class GFG { static void find ( Vector < String > list1 , Vector < String > list2 ) { Vector < String > res = new Vector < > ( ) ; int max_possible_sum = list1 . size ( ) + list2 . size ( ) - 2 ; for ( int sum = 0 ; sum <= max_possible_sum ; sum ++ ) { for ( int i = 0 ; i <= sum ; i ++ ) if ( i < list1 . size ( ) && ( sum - i ) < list2 . size ( ) && list1 . get ( i ) == list2 . get ( sum - i ) ) res . add ( list1 . get ( i ) ) ; if ( res . size ( ) > 0 ) break ; } for ( int i = 0 ; i < res . size ( ) ; i ++ ) System . out . print ( res . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { Vector < String > list1 = new Vector < > ( ) ; list1 . add ( " GeeksforGeeks " ) ; list1 . add ( " Udemy " ) ; list1 . add ( " Coursera " ) ; list1 . add ( " edX " ) ; Vector < String > list2 = new Vector < > ( ) ; list2 . add ( " Codecademy " ) ; list2 . add ( " Khan ▁ Academy " ) ; list2 . add ( " GeeksforGeeks " ) ; find ( list1 , list2 ) ; } }

Accumulator variables: i, sum
Iterator variables: i, sum
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void find ( Vector < String > list1 , Vector < String > list2 ) { Map < String , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < list1 . size ( ) ; i ++ ) map . put ( list1 . get ( i ) , i ) ; Vector < String > res = new Vector < String > ( ) ; int minsum = Integer . MAX_VALUE ; for ( int j = 0 ; j < list2 . size ( ) ; j ++ ) { if ( map . containsKey ( list2 . get ( j ) ) ) { int sum = j + map . get ( list2 . get ( j ) ) ; if ( sum < minsum ) { minsum = sum ; res . clear ( ) ; res . add ( list2 . get ( j ) ) ; } else if ( sum == minsum ) res . add ( list2 . get ( j ) ) ; } } for ( int i = 0 ; i < res . size ( ) ; i ++ ) System . out . print ( res . get ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { Vector < String > list1 = new Vector < String > ( ) ; list1 . add ( " GeeksforGeeks " ) ; list1 . add ( " Udemy " ) ; list1 . add ( " Coursera " ) ; list1 . add ( " edX " ) ; Vector < String > list2 = new Vector < String > ( ) ; list2 . add ( " Codecademy " ) ; list2 . add ( " Khan ▁ Academy " ) ; list2 . add ( " GeeksforGeeks " ) ; find ( list1 , list2 ) ; } }

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