dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static final int MAX = 10 ; @ SuppressWarnings ( " unchecked " ) static Vector < Integer > [ ] adj = new Vector [ MAX ] ; static int min_cost_node ; static void addEdge ( int u , int v ) { adj [ u ] . add ( v ) ; adj [ v ] . add ( u ) ; } static void dfs ( int v , int cost [ ] , boolean vis [ ] ) { vis [ v ] = true ; min_cost_node = Math . min ( min_cost_node , cost [ v - 1 ] ) ; for ( int i = 0 ; i < adj [ v ] . size ( ) ; i ++ ) { if ( vis [ adj [ v ] . get ( i ) ] == false ) { dfs ( adj [ v ] . get ( i ) , cost , vis ) ; } } } static int minimumCost ( int V , int cost [ ] ) { boolean [ ] vis = new boolean [ V + 1 ] ; Arrays . fill ( vis , false ) ; int min_cost = 0 ; for ( int i = 1 ; i <= V ; i ++ ) { if ( ! vis [ i ] ) { min_cost_node = Integer . MAX_VALUE ; dfs ( i , cost , vis ) ; min_cost += min_cost_node ; } } return min_cost ; } public static void main ( String [ ] args ) { int V = 6 , E = 5 ; int cost [ ] = { 12 , 25 , 8 , 11 , 10 , 7 } ; for ( int i = 0 ; i < adj . length ; i ++ ) adj [ i ] = new Vector < Integer > ( ) ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 3 , 2 ) ; addEdge ( 2 , 5 ) ; addEdge ( 4 , 6 ) ; int min_cost = minimumCost ( V , cost ) ; System . out . print ( min_cost + "NEW_LINE"); } }

Index/key variables: MAX, i, u, v
Accumulator variables: i, min_cost
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxm = 0 ; static class Node { int val ; Node left , right ; Node ( int x ) { val = x ; left = null ; right = null ; } } ; static void maxm_setbits ( Node root , int ans ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { ans += Integer . bitCount ( root . val ) ; maxm = Math . max ( ans , maxm ) ; return ; } maxm_setbits ( root . left , ans + Integer . bitCount ( root . val ) ) ; maxm_setbits ( root . right , ans + Integer . bitCount ( root . val ) ) ; } public static void main ( String [ ] args ) { Node root = new Node ( 15 ) ; root . left = new Node ( 3 ) ; root . right = new Node ( 7 ) ; root . left . left = new Node ( 5 ) ; root . left . right = new Node ( 1 ) ; root . right . left = new Node ( 31 ) ; root . right . right = new Node ( 9 ) ; maxm_setbits ( root , 0 ) ; System . out . print ( maxm + "NEW_LINE"); } }

Accumulator variables: ans
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { @ SuppressWarnings ( " unchecked " ) static int getMinimumMoves ( int n , int k , int d , int [ ] a ) { int MAX = 100000 ; Vector < Integer > [ ] v = new Vector [ MAX ] ; for ( int i = 0 ; i < v . length ; i ++ ) v [ i ] = new Vector < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int cnt = 0 ; v [ a [ i ] ] . add ( 0 ) ; while ( a [ i ] > 0 ) { a [ i ] /= d ; cnt ++ ; v [ a [ i ] ] . add ( cnt ) ; } } int ans = Integer . MAX_VALUE ; for ( int i = 0 ; i < MAX ; i ++ ) { if ( v [ i ] . size ( ) >= k ) { int move = 0 ; Collections . sort ( v [ i ] ) ; for ( int j = 0 ; j < k ; j ++ ) { move += v [ i ] . get ( j ) ; } ans = Math . min ( ans , move ) ; } } return ans ; } public static void main ( String [ ] args ) { int N = 5 , K = 3 , D = 2 ; int [ ] A = { 1 , 2 , 3 , 4 , 5 } ; System . out . print ( getMinimumMoves ( N , K , D , A ) ) ; } }

Index/key variables: MAX, i
Accumulator variables: cnt, i, j, move
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int Maxlen ( int arr [ ] , int n ) { int ans = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 0 ) count = 0 ; else count ++ ; ans = Math . max ( ans , count ) ; } return ans ; } public static void main ( String s [ ] ) { int arr [ ] = { 1 , 7 , 2 } ; int n = arr . length ; System . out . println ( Maxlen ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Vector < Integer > get_submaxarr ( int [ ] arr , int n , int y ) { int j = 0 ; Stack < Integer > stk = new Stack < Integer > ( ) ; int [ ] maxarr = new int [ n ] ; Arrays . fill ( maxarr , 0 ) ; stk . push ( 0 ) ; for ( int i = 1 ; i < n ; i ++ ) { while ( stk . size ( ) != 0 && arr [ i ] > arr [ stk . peek ( ) ] ) { maxarr [ stk . peek ( ) ] = i - 1 ; stk . pop ( ) ; } stk . push ( i ) ; } while ( stk . size ( ) != 0 ) { maxarr [ stk . size ( ) ] = n - 1 ; stk . pop ( ) ; } Vector < Integer > submax = new Vector < Integer > ( ) ; for ( int i = 0 ; i <= n - y ; i ++ ) { while ( maxarr [ j ] < i + y - 1 j < i ) { j ++ ; } submax . add ( arr [ j ] ) ; } return submax ; } static Vector < Integer > get_subminarr ( int [ ] arr , int n , int y ) { int j = 0 ; Stack < Integer > stk = new Stack < Integer > ( ) ; int [ ] minarr = new int [ n ] ; Arrays . fill ( minarr , 0 ) ; stk . push ( 0 ) ; for ( int i = 1 ; i < n ; i ++ ) { while ( stk . size ( ) != 0 && arr [ i ] < arr [ stk . peek ( ) ] ) { minarr [ stk . peek ( ) ] = i ; stk . pop ( ) ; } stk . push ( i ) ; } while ( stk . size ( ) != 0 ) { minarr [ stk . peek ( ) ] = n ; stk . pop ( ) ; } Vector < Integer > submin = new Vector < Integer > ( ) ; for ( int i = 0 ; i <= n - y ; i ++ ) { while ( minarr [ j ] <= i + y - 1 j < i ) { j ++ ; } submin . add ( arr [ j ] ) ; } return submin ; } static void getMinDifference ( int [ ] Arr , int N , int Y ) { Vector < Integer > submin = get_subminarr ( Arr , N , Y ) ; Vector < Integer > submax = get_submaxarr ( Arr , N , Y ) ; int minn = submax . get ( 0 ) - submin . get ( 0 ) ; int b = submax . size ( ) ; for ( int i = 1 ; i < b ; i ++ ) { int dif = submax . get ( i ) - submin . get ( i ) + 1 ; minn = Math . min ( minn , dif ) ; } System . out . print ( minn ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 3 , 2 , 2 } ; int N = arr . length ; int Y = 4 ; getMinDifference ( arr , N , Y ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int func ( int A , int B , int C , int x ) { return ( A * x * x + B * x + C ) ; } static int findMinx ( int A , int B , int C , int K ) { int start = 1 ; int end = ( int ) Math . ceil ( Math . sqrt ( K ) ) ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; int x = func ( A , B , C , mid ) ; int Y = func ( A , B , C , mid - 1 ) ; if ( x >= K && Y < K ) { return mid ; } else if ( x < K ) { start = mid + 1 ; } else { end = mid - 1 ; } } return - 1 ; } public static void main ( String [ ] args ) { int A = 3 , B = 4 , C = 5 , K = 6 ; System . out . println ( findMinx ( A , B , C , K ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Map < Integer , ArrayList < Integer > > tree ; static ArrayList < Integer > path ; static int maxHeight , maxHeightNode ; static boolean getDiameterPath ( int vertex , int targetVertex , int parent , ArrayList < Integer > path ) { if ( vertex == targetVertex ) { path . add ( vertex ) ; return true ; } for ( Integer i : tree . get ( vertex ) ) { if ( i == parent ) continue ; if ( getDiameterPath ( i , targetVertex , vertex , path ) ) { path . add ( vertex ) ; return true ; } } return false ; } static void farthestNode ( int vertex , int parent , int height ) { if ( height > maxHeight ) { maxHeight = height ; maxHeightNode = vertex ; } if ( tree . get ( vertex ) != null ) for ( Integer i : tree . get ( vertex ) ) { if ( i == parent ) continue ; farthestNode ( i , vertex , height + 1 ) ; } } static void addedge ( int a , int b ) { if ( tree . get ( a ) == null ) tree . put ( a , new ArrayList < > ( ) ) ; tree . get ( a ) . add ( b ) ; if ( tree . get ( b ) == null ) tree . put ( b , new ArrayList < > ( ) ) ; tree . get ( b ) . add ( a ) ; } static void FindCenter ( int n ) { maxHeight = - 1 ; maxHeightNode = - 1 ; farthestNode ( 0 , - 1 , 0 ) ; int leaf1 = maxHeightNode ; maxHeight = - 1 ; farthestNode ( maxHeightNode , - 1 , 0 ) ; int leaf2 = maxHeightNode ; path = new ArrayList < > ( ) ; getDiameterPath ( leaf1 , leaf2 , - 1 , path ) ; int pathSize = path . size ( ) ; if ( pathSize % 2 == 1 ) { System . out . println ( path . get ( pathSize / 2 ) ) ; } else { System . out . println ( path . get ( pathSize / 2 ) + " , ▁ " + path . get ( ( pathSize - 1 ) / 2 ) ) ; } } public static void main ( String [ ] args ) { int N = 4 ; tree = new HashMap < > ( ) ; addedge ( 1 , 0 ) ; addedge ( 1 , 2 ) ; addedge ( 1 , 3 ) ; FindCenter ( N ) ; } }

Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int maxm = 1000000000 ; static int count ( int [ ] v , int n ) { int i , odd = 0 , even = 0 ; int j , d , count ; int t = ( int ) 1 << v . length ; int size = v . length ; for ( i = 1 ; i < t ; i ++ ) { d = 1 ; count = 0 ; for ( j = 0 ; j < size ; j ++ ) { if ( ( i & ( 1 << j ) ) > 0 ) { d *= v [ j ] ; count ++ ; } } if ( count % 2 == 1 ) odd += n / d ; else even += n / d ; } return ( odd - even ) ; } static int BinarySearch ( int l , int r , int [ ] v , int key ) { int mid ; while ( r - l > 1 ) { mid = ( l + r ) / 2 ; if ( key <= count ( v , mid ) ) { r = mid ; } else { l = mid ; } } if ( key == count ( v , l ) ) return l ; else return r ; } public static void main ( String [ ] args ) { int N = 2 , K = 10 ; int [ ] v = { 2 , 3 } ; System . out . print ( BinarySearch ( 1 , maxm , v , K ) + "NEW_LINE"); } }

Index/key variables: j
Accumulator variables: count, d, even, i, j, odd
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . HashMap ; import java . util . LinkedList ; import java . util . Map ; import java . util . Queue ; class Geeks { static void minDistancePoints ( int A [ ] , int K , int n ) { Map < Integer , Boolean > m = new HashMap < Integer , Boolean > ( ) ; Queue < Integer > q = new LinkedList < Integer > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { m . put ( A [ i ] , true ) ; q . add ( A [ i ] ) ; } LinkedList < Integer > ans = new LinkedList < Integer > ( ) ; while ( K > 0 ) { int x = q . poll ( ) ; if ( ! m . containsKey ( x - 1 ) && K > 0 ) { m . put ( x - 1 , true ) ; q . add ( x - 1 ) ; ans . add ( x - 1 ) ; K -- ; } if ( ! m . containsKey ( x + 1 ) && K > 0 ) { m . put ( x + 1 , true ) ; q . add ( x + 1 ) ; ans . add ( x + 1 ) ; K -- ; } } for ( Integer i : ans ) System . out . print ( i + " ▁ " ) ; } public static void main ( String [ ] args ) { int A [ ] = new int [ ] { - 1 , 4 , 6 } ; int K = 3 ; int n = A . length ; minDistancePoints ( A , K , n ) ; } }

Index/key variables: i
Accumulator variables: K
Iterator variables: i
Class/struct names: Geeks
Java program:
import java . util . * ; class GFG { static final int N = 3 ; static int search ( int mat [ ] [ ] , int n , int m ) { int i , a = Integer . MAX_VALUE ; for ( i = 0 ; i < n ; i ++ ) { int low = 0 ; int high = m - 1 ; int mid ; int ans = Integer . MAX_VALUE ; while ( low <= high ) { mid = ( low + high ) / 2 ; if ( mat [ i ] [ mid ] == 1 ) { if ( mid == 0 ) { ans = 0 ; break ; } else if ( mat [ i ] [ mid - 1 ] == 0 ) { ans = mid ; break ; } } if ( mat [ i ] [ mid ] == 1 ) high = mid - 1 ; else low = mid + 1 ; } if ( ans < a ) a = ans ; } if ( a == Integer . MAX_VALUE ) return - 1 ; return a + 1 ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 0 , 0 , 0 } , { 0 , 0 , 1 } , { 0 , 1 , 1 } } ; System . out . print ( search ( mat , 3 , 3 ) ) ; } }

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class pair { char first ; int second ; public pair ( char first , int second ) { this . first = first ; this . second = second ; } } static void maxSubString ( char [ ] S , int K , int N ) { int [ ] freq = new int [ 26 ] ; for ( int i = 0 ; i < N ; ++ i ) { freq [ S [ i ] - ' a ' ] = 1 ; } Vector < pair > answer = new Vector < pair > ( ) ; for ( int i = 0 ; i < 26 ; ++ i ) { if ( freq [ i ] == 0 ) continue ; char ch = ( char ) ( i + 97 ) ; int count = 0 ; int index = - 1 ; for ( int j = 0 ; j < N ; ++ j ) { if ( S [ j ] == ch ) count ++ ; if ( count == K ) index = j ; } answer . add ( new pair ( ch , index ) ) ; } int flag = 0 ; for ( int i = 0 ; i < ( int ) answer . size ( ) ; ++ i ) { if ( answer . get ( i ) . second > - 1 ) { flag = 1 ; System . out . print ( answer . get ( i ) . first + " ▁ " + answer . get ( i ) . second + "NEW_LINE"); } } if ( flag == 0 ) System . out . print ( " - 1" + "NEW_LINE"); } public static void main ( String [ ] args ) { String S = " cbaabaacbcd " ; int K = 2 ; int N = S . length ( ) ; maxSubString ( S . toCharArray ( ) , K , N ) ; } }

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Class/struct names: GFG, pair
Java program:
class GFG { static void greaterK ( int n , int k ) { int [ ] p = new int [ String . valueOf ( n ) . length ( ) + 2 ] ; int index = 0 ; int x = n ; while ( x > 0 ) { p [ index ] = ( int ) ( x % k ) ; x /= k ; index ++ ; } int idx = 0 ; for ( int i = 0 ; i < p . length - 1 ; ++ i ) { if ( p [ i ] >= 2 ) { p [ i ] = 0 ; p [ i + 1 ] ++ ; for ( int j = idx ; j < i ; ++ j ) { p [ j ] = 0 ; } idx = i + 1 ; } if ( p [ i ] == k ) { p [ i ] = 0 ; p [ i + 1 ] ++ ; } } int j = p . length - 1 ; if ( p [ j ] >= 2 ) { p [ index ] = 1 ; index ++ ; } int ans = 0 ; for ( int i = p . length - 1 ; i >= 0 ; -- i ) { ans = ans * k + p [ i ] ; } System . out . print ( ans + "NEW_LINE"); } public static void main ( String [ ] args ) { int n = 29 , k = 7 ; greaterK ( n , k ) ; } }

Index/key variables: i, index, j
Accumulator variables: index, x
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static boolean canBeBalanced ( String s , int n ) { int count = 0 , count_1 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . charAt ( i ) == ' ( ' ) count ++ ; else count -- ; count_1 = Math . min ( count_1 , count ) ; } if ( count_1 >= - 1 && count == 0 ) return true ; return false ; } public static void main ( String [ ] args ) { String s = " ( ) ) ( ) ( " ; int n = s . length ( ) ; if ( canBeBalanced ( s , n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int max_element ( int [ ] arr ) { int max = arr [ 0 ] ; for ( int ele : arr ) if ( max < ele ) max = ele ; return max ; } static int calculateDifference ( int [ ] arr , int n ) { int max_val = max_element ( arr ) ; boolean [ ] prime = new boolean [ max_val + 1 ] ; Arrays . fill ( prime , true ) ; prime [ 0 ] = false ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= max_val ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * 2 ; i <= max_val ; i += p ) prime [ i ] = false ; } } int x1 = 1 , x2 = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( prime [ arr [ i ] ] ) x1 ^= arr [ i ] ; else if ( arr [ i ] != 1 ) x2 ^= arr [ i ] ; } return Math . abs ( x1 - x2 ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 5 , 10 , 15 , 7 } ; int n = arr . length ; System . out . println ( calculateDifference ( arr , n ) ) ; } }

Index/key variables: i, p
Accumulator variables: i, p, x1, x2
Iterator variables: ele, i, p
Class/struct names: GFG
Java program:
class GFG { static class Node { int data ; Node next ; } ; static Node insert ( Node head , int item ) { Node temp = new Node ( ) ; temp . data = item ; temp . next = head ; head = temp ; return head ; } static int countNode ( Node head ) { int count = 0 ; while ( head . next != null ) { Node ptr = head . next ; while ( ptr != null ) { if ( head . data == ptr . data ) { count ++ ; break ; } ptr = ptr . next ; } head = head . next ; } return count ; } public static void main ( String args [ ] ) { Node head = null ; head = insert ( head , 5 ) ; head = insert ( head , 7 ) ; head = insert ( head , 5 ) ; head = insert ( head , 1 ) ; head = insert ( head , 7 ) ; System . out . println ( countNode ( head ) ) ; } }

Accumulator variables: count
Class/struct names: GFG, Node
Java program:
import java . io . * ; import java . util . * ; class GFG { static boolean isPossible ( String A , String B , int b , int m ) { List < List < Integer > > S = new ArrayList < List < Integer > > ( ) ; for ( int i = 0 ; i < 26 ; i ++ ) S . add ( new ArrayList < Integer > ( ) ) ; int [ ] box = new int [ A . length ( ) ] ; for ( int i = 0 ; i < A . length ( ) ; i ++ ) { S . get ( A . charAt ( i ) - ' a ' ) . add ( i ) ; } int low = 0 ; for ( int i = 0 ; i < B . length ( ) ; i ++ ) { List < Integer > indexes = S . get ( B . charAt ( i ) - ' a ' ) ; int it = lower_bound ( indexes , low ) ; if ( it == indexes . size ( ) ) return false ; int count = indexes . get ( it ) / b ; box [ count ] = box [ count ] + 1 ; if ( box [ count ] >= m ) { count ++ ; low = ( count ) * b ; } else low = indexes . get ( it ) + 1 ; } return true ; } static int lower_bound ( List < Integer > indexes , int k ) { int low = 0 , high = indexes . size ( ) - 1 ; while ( low < high ) { int mid = ( low + high ) / 2 ; if ( indexes . get ( mid ) < k ) low = mid + 1 ; else high = mid ; } return ( indexes . get ( low ) < k ) ? low + 1 : low ; } public static void main ( String [ ] args ) { String A = " abcbbcdefxyz " ; String B = " acdxyz " ; int b = 5 ; int m = 2 ; if ( isPossible ( A , B , b , m ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: count
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxSumArray ( int arr [ ] , int n ) { int sum = 0 ; Map < Integer , Integer > m = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( m . containsKey ( arr [ i ] ) ) { m . put ( arr [ i ] , m . get ( arr [ i ] ) + 1 ) ; } else { m . put ( arr [ i ] , 1 ) ; } } int minimum = Integer . MAX_VALUE ; for ( Map . Entry < Integer , Integer > x : m . entrySet ( ) ) minimum = Math . min ( minimum , x . getValue ( ) * x . getKey ( ) ) ; return ( sum - minimum ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 , 3 , 3 , 2 , 2 , 1 , 1 , 1 } ; int n = arr . length ; System . out . println ( maxSumArray ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX = 1001 ; static int prefix [ ] [ ] = new int [ MAX ] [ MAX ] ; static int ar [ ] = new int [ MAX ] ; static void cal_prefix ( int n , int arr [ ] ) { int i , j ; for ( i = 0 ; i < n ; i ++ ) ar [ i + 1 ] = arr [ i ] ; for ( i = 1 ; i <= 1000 ; i ++ ) { for ( j = 0 ; j <= n ; j ++ ) prefix [ i ] [ j ] = 0 ; for ( j = 1 ; j <= n ; j ++ ) { prefix [ i ] [ j ] = prefix [ i ] [ j - 1 ] + ( int ) ( ar [ j ] <= i ? 1 : 0 ) ; } } } static int ksub ( int l , int r , int n , int k ) { int lo , hi , mid ; lo = 1 ; hi = 1000 ; while ( lo + 1 < hi ) { mid = ( lo + hi ) / 2 ; if ( prefix [ mid ] [ r ] - prefix [ mid ] [ l - 1 ] >= k ) hi = mid ; else lo = mid + 1 ; } if ( prefix [ lo ] [ r ] - prefix [ lo ] [ l - 1 ] >= k ) hi = lo ; return hi ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 4 , 2 , 3 , 5 , 7 , 6 } ; int n = arr . length ; int k = 4 ; cal_prefix ( n , arr ) ; int queries [ ] [ ] = { { 1 , n , 1 } , { 2 , n - 2 , 2 } , { 3 , n - 1 , 3 } } ; int q = queries . length ; for ( int i = 0 ; i < q ; i ++ ) System . out . println ( ksub ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , n , queries [ i ] [ 2 ] ) ) ; } }

Index/key variables: MAX, i, j, lo, mid, r
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; public class Main { class DisjointUnionSets { int [ ] rank , parent ; int n ; public DisjointUnionSets ( int n ) { rank = new int [ n ] ; parent = new int [ n ] ; this . n = n ; makeSet ( ) ; } void makeSet ( ) { for ( int i = 0 ; i < n ; i ++ ) parent [ i ] = i ; } int find ( int x ) { if ( parent [ x ] != x ) { return find ( parent [ x ] ) ; } return x ; } void union ( int x , int y ) { int xRoot = find ( x ) ; int yRoot = find ( y ) ; if ( xRoot == yRoot ) return ; if ( rank [ xRoot ] < rank [ yRoot ] ) parent [ xRoot ] = yRoot ; else if ( rank [ yRoot ] < rank [ xRoot ] ) parent [ yRoot ] = xRoot ; else { parent [ yRoot ] = xRoot ; rank [ xRoot ] = rank [ xRoot ] + 1 ; } } } static int countIslands ( int a [ ] [ ] ) { int n = a . length ; int m = a [ 0 ] . length ; DisjointUnionSets dus = new DisjointUnionSets ( n * m ) ; for ( int j = 0 ; j < n ; j ++ ) { for ( int k = 0 ; k < m ; k ++ ) { if ( a [ j ] [ k ] == 0 ) continue ; if ( j + 1 < n && a [ j + 1 ] [ k ] == 1 ) dus . union ( j * ( m ) + k , ( j + 1 ) * ( m ) + k ) ; if ( j - 1 >= 0 && a [ j - 1 ] [ k ] == 1 ) dus . union ( j * ( m ) + k , ( j - 1 ) * ( m ) + k ) ; if ( k + 1 < m && a [ j ] [ k + 1 ] == 1 ) dus . union ( j * ( m ) + k , ( j ) * ( m ) + k + 1 ) ; if ( k - 1 >= 0 && a [ j ] [ k - 1 ] == 1 ) dus . union ( j * ( m ) + k , ( j ) * ( m ) + k - 1 ) ; if ( j + 1 < n && k + 1 < m && a [ j + 1 ] [ k + 1 ] == 1 ) dus . union ( j * ( m ) + k , ( j + 1 ) * ( m ) + k + 1 ) ; if ( j + 1 < n && k - 1 >= 0 && a [ j + 1 ] [ k - 1 ] == 1 ) dus . union ( j * m + k , ( j + 1 ) * ( m ) + k - 1 ) ; if ( j - 1 >= 0 && k + 1 < m && a [ j - 1 ] [ k + 1 ] == 1 ) dus . union ( j * m + k , ( j - 1 ) * m + k + 1 ) ; if ( j - 1 >= 0 && k - 1 >= 0 && a [ j - 1 ] [ k - 1 ] == 1 ) dus . union ( j * m + k , ( j - 1 ) * m + k - 1 ) ; } } int [ ] c = new int [ n * m ] ; int numberOfIslands = 0 ; for ( int j = 0 ; j < n ; j ++ ) { for ( int k = 0 ; k < m ; k ++ ) { if ( a [ j ] [ k ] == 1 ) { int x = dus . find ( j * m + k ) ; if ( c [ x ] == 0 ) { numberOfIslands ++ ; c [ x ] ++ ; } else c [ x ] ++ ; } } } return numberOfIslands ; } } public static void main ( String [ ] args ) throws IOException { int [ ] [ ] a = new int [ ] [ ] { { 1 , 1 , 0 , 0 , 0 } , { 0 , 1 , 0 , 0 , 1 } , { 1 , 0 , 0 , 1 , 1 } , { 0 , 0 , 0 , 0 , 0 } , { 1 , 0 , 1 , 0 , 1 } } ; System . out . println ( " Number ▁ of ▁ Islands ▁ is : ▁ " + countIslands ( a ) ) ; }

Index/key variables: i, j, k, n, x, xRoot, yRoot
Accumulator variables: i, j, k, numberOfIslands
Iterator variables: i, j, k
Class/struct names: DisjointUnionSets, Main
Java program:
class GFG { static long squareSum ( long N ) { long sum = ( long ) ( N * ( N + 1 ) * ( 2 * N + 1 ) ) / 6 ; return sum ; } static long findMaxN ( long X ) { long N = ( long ) Math . sqrt ( X ) ; for ( long i = 1 ; i <= N ; i ++ ) { if ( squareSum ( i ) > X ) return i - 1 ; } return - 1 ; } public static void main ( String [ ] args ) { long X = 25 ; System . out . println ( findMaxN ( X ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int max_min ( int a [ ] , int n ) { if ( n <= 1 ) return Integer . MAX_VALUE ; int f_min = a [ 0 ] , s_min = Integer . MAX_VALUE ; int f_max = a [ 0 ] , s_max = Integer . MIN_VALUE ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= f_min ) { s_min = f_min ; f_min = a [ i ] ; } else if ( a [ i ] < s_min ) { s_min = a [ i ] ; } if ( a [ i ] >= f_max ) { s_max = f_max ; f_max = a [ i ] ; } else if ( a [ i ] > s_max ) { s_max = a [ i ] ; } } return Math . min ( ( f_max - s_min ) , ( s_max - f_min ) ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 3 , 7 } ; int n = a . length ; System . out . println ( max_min ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class Solution { static int minimal ( int a [ ] , int n ) { int lo = 0 , hi = n - 1 ; while ( lo < hi ) { int mid = ( lo + hi ) >> 1 ; if ( a [ mid ] < a [ mid + 1 ] ) { hi = mid ; } else { lo = mid + 1 ; } } return lo ; } public static void main ( String args [ ] ) { int a [ ] = { 8 , 5 , 4 , 3 , 4 , 10 } ; int n = a . length ; int ind = minimal ( a , n ) ; System . out . println ( a [ ind ] ) ; } }

Index/key variables: ind, mid
Class/struct names: Solution