dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static class Pair { int first ; int second ; Pair ( int first , int second ) { this . first = first ; this . second = second ; } } public static int lower_bound ( int arr [ ] , int key ) { int l = - 1 , r = arr . length ; while ( l + 1 < r ) { int m = ( l + r ) >>> 1 ; if ( arr [ m ] >= key ) r = m ; else l = m ; } return r ; } public static int upper_bound ( int arr [ ] , int key ) { int l = - 1 , r = arr . length ; while ( l + 1 < r ) { int m = ( l + r ) >>> 1 ; if ( arr [ m ] <= key ) l = m ; else r = m ; } return l + 1 ; } static void minSegments ( Pair segments [ ] , int n ) { int startPoints [ ] = new int [ n ] ; int endPoints [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { startPoints [ i ] = segments [ i ] . first ; endPoints [ i ] = segments [ i ] . second ; } Arrays . sort ( startPoints ) ; Arrays . sort ( endPoints ) ; int ans = n - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int f = segments [ i ] . first ; int s = segments [ i ] . second ; int leftDelete = lower_bound ( endPoints , f ) ; int rightDelete = Math . max ( 0 , n - ( int ) ( upper_bound ( startPoints , s ) ) ) ; ans = Math . min ( ans , leftDelete + rightDelete ) ; } System . out . println ( ans ) ; } public static void main ( String [ ] args ) { Pair arr [ ] = { new Pair ( 1 , 2 ) , new Pair ( 5 , 6 ) , new Pair ( 6 , 7 ) , new Pair ( 7 , 10 ) , new Pair ( 8 , 9 ) } ; int N = arr . length ; minSegments ( arr , N ) ; } }

Index/key variables: i, m, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Pair
Java program:
import java . util . * ; class GFG { static void longestSubString ( char [ ] s , int k ) { int ans = 0 ; int freq [ ] = new int [ 26 ] ; int n = s . length ; for ( int i = 0 ; i < n ; i ++ ) freq [ s [ i ] - ' a ' ] ++ ; int unique = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) if ( freq [ i ] != 0 ) unique ++ ; for ( int curr_unique = 1 ; curr_unique <= unique ; curr_unique ++ ) { Arrays . fill ( freq , 0 ) ; int start = 0 , end = 0 ; int cnt = 0 , count_k = 0 ; while ( end < n ) { if ( cnt <= curr_unique ) { int ind = s [ end ] - ' a ' ; if ( freq [ ind ] == 0 ) cnt ++ ; freq [ ind ] ++ ; if ( freq [ ind ] == k ) count_k ++ ; end ++ ; } else { int ind = s [ start ] - ' a ' ; if ( freq [ ind ] == k ) count_k -- ; freq [ ind ] -- ; if ( freq [ ind ] == 0 ) cnt -- ; start ++ ; } if ( cnt == curr_unique && count_k == curr_unique ) ans = Math . max ( ans , end - start ) ; } } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { String S = " aabbba " ; int K = 3 ; longestSubString ( S . toCharArray ( ) , K ) ; } }

Index/key variables: end, i, ind, start
Accumulator variables: cnt, count_k, curr_unique, end, i, start, unique
Iterator variables: curr_unique, i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static class Pair { int first ; int second ; public Pair ( int first , int second ) { this . first = first ; this . second = second ; } @ Override public int hashCode ( ) { final int prime = 31 ; int result = 1 ; result = prime * result + first ; result = prime * result + second ; return result ; } @ Override public boolean equals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; Pair other = ( Pair ) obj ; if ( first != other . first ) return false ; if ( second != other . second ) return false ; return true ; } } static void findMaxIntervals ( ArrayList < Pair > v , int n ) { HashMap < Pair , Integer > um = new HashMap < > ( ) ; Collections . sort ( v , ( x , y ) -> x . first - y . first ) ; for ( int i = 0 ; i < n ; i ++ ) { um . put ( v . get ( i ) , 0 ) ; int start = v . get ( i ) . first ; int end = v . get ( i ) . second ; int low = i + 1 ; int high = n - 1 ; int ans = - 1 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( v . get ( mid ) . first > end ) { ans = mid ; high = mid - 1 ; } else { low = mid + 1 ; } } if ( ans != - 1 ) um . put ( v . get ( i ) , n - ans ) ; } Collections . sort ( v , ( x , y ) -> x . second - y . second ) ; for ( int i = 0 ; i < n ; i ++ ) { int start = v . get ( i ) . first ; int end = v . get ( i ) . second ; int low = 0 ; int high = i - 1 ; int ans = - 1 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( v . get ( mid ) . second < start ) { ans = mid ; low = mid + 1 ; } else { high = mid - 1 ; } } if ( ans != - 1 ) um . put ( v . get ( i ) , um . get ( v . get ( i ) ) + ( ans + 1 ) ) ; } int res = 0 ; for ( int second : um . values ( ) ) { res = Math . max ( res , n - second ) ; } System . out . println ( res ) ; } public static void main ( String [ ] args ) { ArrayList < Pair > arr = new ArrayList < > ( ) ; arr . add ( new Pair ( 1 , 2 ) ) ; arr . add ( new Pair ( 3 , 4 ) ) ; arr . add ( new Pair ( 2 , 5 ) ) ; int N = arr . size ( ) ; findMaxIntervals ( arr , N ) ; } }

Accumulator variables: i
Iterator variables: i, second
Class/struct names: GFG, Pair
Java program:
import java . util . * ; class GFG { static int dRow [ ] = { - 1 , 0 , 1 , 0 } ; static int dCol [ ] = { 0 , 1 , 0 , - 1 } ; static boolean isValid ( boolean [ ] [ ] vis , int row , int col , int COL , int ROW ) { if ( row < 0 col < 0 col > COL - 1 row > ROW - 1 ) return false ; if ( vis [ row ] [ col ] == true ) return false ; return true ; } static void DFSUtil ( int row , int col , int [ ] [ ] grid , boolean [ ] [ ] vis , int M , int N ) { vis [ row ] [ col ] = true ; System . out . print ( grid [ row ] [ col ] + " ▁ " ) ; for ( int i = 0 ; i < 4 ; i ++ ) { int x = row + dRow [ i ] ; int y = col + dCol [ i ] ; if ( isValid ( vis , x , y , M , N ) ) DFSUtil ( x , y , grid , vis , M , N ) ; } } static void DFS ( int row , int col , int [ ] [ ] grid , int M , int N ) { boolean [ ] [ ] vis = new boolean [ M + 1 ] [ N + 1 ] ; for ( int i = 0 ; i < M + 1 ; i ++ ) { for ( int j = 0 ; j < N + 1 ; j ++ ) { vis [ i ] [ j ] = false ; } } DFSUtil ( 0 , 0 , grid , vis , M , N ) ; } public static void main ( String args [ ] ) { int [ ] [ ] grid = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; int M = grid . length ; int N = grid [ 0 ] . length ; DFS ( 0 , 0 , grid , M , N ) ; } }

Index/key variables: col, i, j, row
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; public class Main { public static class Pair { int Item1 , Item2 ; public Pair ( int Item1 , int Item2 ) { this . Item1 = Item1 ; this . Item2 = Item2 ; } } static int [ ] dRow = { - 1 , 0 , 1 , 0 } ; static int [ ] dCol = { 0 , 1 , 0 , - 1 } ; static Vector < Vector < Boolean > > vis ; static boolean isValid ( int row , int col , int COL , int ROW ) { if ( row < 0 col < 0 col > COL - 1 row > ROW - 1 ) return false ; if ( vis . get ( row ) . get ( col ) == true ) return false ; return true ; } static void DFS_iterative ( int [ ] [ ] grid , int M , int N ) { vis = new Vector < Vector < Boolean > > ( ) ; for ( int i = 0 ; i < M + 5 ; i ++ ) { vis . add ( new Vector < Boolean > ( ) ) ; for ( int j = 0 ; j < N + 5 ; j ++ ) { vis . get ( i ) . add ( false ) ; } } Vector < Pair > st = new Vector < Pair > ( ) ; st . add ( new Pair ( 0 , 0 ) ) ; vis . get ( 0 ) . set ( 0 , true ) ; while ( st . size ( ) > 0 ) { Pair p = st . get ( st . size ( ) - 1 ) ; st . remove ( st . size ( ) - 1 ) ; int row = p . Item1 ; int col = p . Item2 ; System . out . print ( grid [ row ] [ col ] + " ▁ " ) ; for ( int i = 0 ; i < 4 ; i ++ ) { int x = row + dRow [ i ] ; int y = col + dCol [ i ] ; if ( isValid ( x , y , M , N ) ) { st . add ( new Pair ( x , y ) ) ; vis . get ( x ) . set ( y , true ) ; } } } } public static void main ( String [ ] args ) { int [ ] [ ] grid = { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; int M = 4 ; int N = 4 ; DFS_iterative ( grid , M , N ) ; } }

Index/key variables: col, i, row
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Main, Pair
Java program:
import java . io . * ; import java . util . * ; class GFG { static void minOps ( String s , int N ) { int ans = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( s . charAt ( i ) != s . charAt ( i - 1 ) ) { ans ++ ; } } if ( ans % 2 == 1 ) { System . out . print ( ( ans - 1 ) / 2 ) ; return ; } System . out . print ( ans / 2 ) ; } public static void main ( String [ ] args ) { String str = "01011100" ; int N = str . length ( ) ; minOps ( str , N ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int MAX = 1000001 ; static boolean [ ] prime = new boolean [ MAX ] ; static int [ ] cntTriplet = new int [ MAX ] ; static void primeTriplet ( int N ) { Arrays . fill ( prime , true ) ; prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i * i <= N ; i ++ ) { if ( prime [ i ] ) { for ( int j = i * i ; j <= N ; j += i ) { prime [ j ] = false ; } } } for ( int i = 3 ; i <= N ; i ++ ) { if ( prime [ i ] && prime [ i - 2 ] ) { cntTriplet [ i ] = cntTriplet [ i - 1 ] + 1 ; } else { cntTriplet [ i ] = cntTriplet [ i - 1 ] ; } } System . out . println ( cntTriplet [ N ] ) ; } public static void main ( String [ ] args ) { int N = 7 ; primeTriplet ( N ) ; } }

Index/key variables: MAX, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
public class gfg { static void count ( int a [ ] , int n ) { if ( n == 1 ) { System . out . print ( 0 ) ; return ; } int [ ] pre = new int [ n - 1 ] ; int [ ] suf = new int [ n - 1 ] ; int max = a [ 0 ] ; int ans = 0 , i ; pre [ 0 ] = a [ 0 ] ; for ( i = 1 ; i < n - 1 ; i ++ ) { if ( a [ i ] > max ) max = a [ i ] ; pre [ i ] = max ; } max = a [ n - 1 ] ; suf [ n - 2 ] = a [ n - 1 ] ; for ( i = n - 2 ; i >= 1 ; i -- ) { if ( a [ i ] > max ) max = a [ i ] ; suf [ i - 1 ] = max ; } for ( i = 0 ; i < n - 1 ; i ++ ) { if ( pre [ i ] < suf [ i ] ) ans ++ ; } System . out . print ( ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 8 , 1 , 4 } ; int N = arr . length ; count ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: ans, 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 ; HashMap < Integer , Integer > map = new HashMap < > ( ) ; int dp [ ] = new int [ n ] ; map . put ( a [ 0 ] , 1 ) ; dp [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { Integer dpj = map . get ( a [ i ] ^ k ) ; if ( dpj != null ) dp [ i ] = Math . max ( dp [ i ] , dpj + 1 ) ; ans = Math . max ( ans , dp [ i ] ) ; map . put ( a [ i ] , Math . max ( map . getOrDefault ( a [ i ] , 1 ) , dp [ i ] ) ) ; } return ans >= 2 ? ans : 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 4 , 3 , 5 } ; int N = arr . length ; int K = 1 ; System . out . println ( xorSubsequence ( arr , N , K ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int ans ; static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static class TreeNode { int data ; TreeNode left ; TreeNode right ; } ; static TreeNode newNode ( int data ) { TreeNode Node = new TreeNode ( ) ; Node . data = data ; Node . left = null ; Node . right = null ; return ( Node ) ; } static pair sumofsubtree ( TreeNode root ) { pair p = new pair ( 1 , 0 ) ; if ( root . left != null ) { pair ptemp = sumofsubtree ( root . left ) ; p . second += ptemp . first + ptemp . second ; p . first += ptemp . first ; } if ( root . right != null ) { pair ptemp = sumofsubtree ( root . right ) ; p . second += ptemp . first + ptemp . second ; p . first += ptemp . first ; } ans += p . second ; return p ; } public static void main ( String [ ] args ) { TreeNode root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . left . left . left = newNode ( 8 ) ; root . left . left . right = newNode ( 9 ) ; ans = 0 ; sumofsubtree ( root ) ; System . out . print ( ans ) ; } }

Accumulator variables: ans, first, second
Class/struct names: GFG, TreeNode, pair
Java program:
import java . io . * ; import java . util . * ; class GFG { public static void minTime ( int arr [ ] , int N , int K ) { Queue < Integer > q = new LinkedList < > ( ) ; boolean vis [ ] = new boolean [ N + 1 ] ; int time = 0 ; for ( int i = 0 ; i < K ; i ++ ) { q . add ( arr [ i ] ) ; vis [ arr [ i ] ] = true ; } while ( q . size ( ) > 0 ) { for ( int i = 0 ; i < q . size ( ) ; i ++ ) { int curr = q . poll ( ) ; if ( curr - 1 >= 1 && ! vis [ curr - 1 ] ) { vis [ curr - 1 ] = true ; q . add ( curr - 1 ) ; } if ( curr + 1 <= N && ! vis [ curr + 1 ] ) { vis [ curr + 1 ] = true ; q . add ( curr + 1 ) ; } } time ++ ; } System . out . println ( time - 1 ) ; } public static void main ( String [ ] args ) { int N = 6 ; int arr [ ] = { 2 , 6 } ; int K = arr . length ; minTime ( arr , N , K ) ; } }

Index/key variables: i
Accumulator variables: i, time
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class Main { static final int MAXL = 17 ; static int N ; static long [ ] v ; static long findN ( int D ) { if ( D % 9 != 0 ) return 0 ; D /= 9 ; long [ ] B = new long [ MAXL ] ; B [ 0 ] = 1 ; for ( int i = 1 ; i < MAXL ; i ++ ) { B [ i ] = B [ i - 1 ] * 10 ; } long ans = 0 ; for ( int i = 1 ; i <= MAXL ; i ++ ) { N = ( i + 1 ) / 2 ; v = new long [ N ] ; for ( int j = 0 ; j < N ; j ++ ) for ( int k = j ; k < i - j ; k ++ ) v [ j ] += B [ k ] ; ans += count ( D , i , 0 , new int [ N ] ) ; } return ans ; } static long count ( long D , int l , int t , int [ ] x ) { if ( t == N ) { if ( D != 0 ) return 0 ; long ans = 1 ; for ( int i = 0 ; i < N ; i ++ ) { ans *= ( i == 0 ? 9 : 10 ) - Math . abs ( x [ i ] ) ; } if ( l % 2 == 0 ) { ans *= 10 ; } return ans ; } long ans = 0 ; for ( int m = - 9 ; m <= 9 ; m ++ ) { if ( - v [ t ] < D + v [ t ] * m && D + v [ t ] * m < v [ t ] ) { x [ t ] = m ; ans += count ( D + v [ t ] * m , l , t + 1 , x ) ; } } return ans ; } public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System . in ) ; int D = 63 ; System . out . println ( findN ( D ) ) ; sc . close ( ) ; } }

Index/key variables: MAXL, N, i, j, k, t
Accumulator variables: D, ans, i, j, k, m
Iterator variables: i, j, k, m
Class/struct names: Main
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int findPeak ( ArrayList < Integer > arr ) { int left = 0 ; int right = arr . size ( ) - 1 ; while ( left < right ) { int mid = left + ( right - left ) / 2 ; if ( arr . get ( mid ) < arr . get ( mid + 1 ) ) { left = mid + 1 ; } else { right = mid ; } } return left ; } static int BS ( int X , int left , int right , ArrayList < Integer > arr ) { while ( left <= right ) { int mid = left + ( right - left ) / 2 ; if ( arr . get ( mid ) == X ) { return mid ; } else if ( X > arr . get ( mid ) ) { left = mid + 1 ; } else { right = mid - 1 ; } } return - 1 ; } static int reverseBS ( int X , int left , int right , ArrayList < Integer > arr ) { while ( left <= right ) { int mid = left + ( right - left ) / 2 ; if ( arr . get ( mid ) == X ) { return mid ; } else if ( X > arr . get ( mid ) ) { right = mid - 1 ; } else { left = mid + 1 ; } } return - 1 ; } static void findInMA ( int X , ArrayList < Integer > mountainArr ) { int peakIndex = findPeak ( mountainArr ) ; int res = - 1 ; if ( X >= mountainArr . get ( 0 ) && X <= mountainArr . get ( peakIndex ) ) { res = BS ( X , 0 , peakIndex , mountainArr ) ; } if ( res == - 1 ) { res = reverseBS ( X , peakIndex + 1 , mountainArr . size ( ) - 1 , mountainArr ) ; } System . out . println ( res ) ; } public static void main ( String [ ] args ) { int X = 3 ; ArrayList < Integer > list = new ArrayList < > ( Arrays . asList ( 1 , 2 , 3 , 4 , 5 , 3 , 1 ) ) ; findInMA ( X , list ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int count ( int [ ] a ) { int counter = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { if ( a [ i ] == 0 ) { counter ++ ; } } return counter ; } static void rearrange ( int [ ] a , int n , int x ) { for ( int i = 0 ; i < n ; i ++ ) a [ i ] = Math . abs ( a [ i ] ) ; Arrays . sort ( a ) ; x = n - x ; int z = count ( a ) ; if ( x > n - z ) { System . out . println ( " - 1" ) ; return ; } for ( int i = 0 ; i < n && x > 0 ; i += 2 ) { a [ i ] = - a [ i ] ; x -- ; } for ( int i = n - 1 ; i >= 0 && x > 0 ; i -- ) { if ( a [ i ] > 0 ) { a [ i ] = - a [ i ] ; x -- ; } } for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( a [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 0 , - 2 , 4 , 5 , - 3 } ; int K = 3 ; int N = arr . length ; rearrange ( arr , N , K ) ; } }

Index/key variables: i
Accumulator variables: counter, i, x
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxSubarrayProduct ( Vector < Integer > arr , int n ) { int max_ending_here = 1 ; int min_ending_here = 1 ; int max_so_far = 0 ; int flag = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr . get ( i ) > 0 ) { max_ending_here = max_ending_here * arr . get ( i ) ; min_ending_here = Math . min ( min_ending_here * arr . get ( i ) , 1 ) ; flag = 1 ; } else if ( arr . get ( i ) == 0 ) { max_ending_here = 1 ; min_ending_here = 1 ; } else { int temp = max_ending_here ; max_ending_here = Math . max ( min_ending_here * arr . get ( i ) , 1 ) ; min_ending_here = temp * arr . get ( i ) ; } if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } if ( flag == 0 && max_so_far == 0 ) return 0 ; return max_so_far ; } static int findMaxProduct ( int [ ] a , int n ) { int i = 0 ; int maxProd = 1 ; while ( i < n ) { Vector < Integer > v = new Vector < > ( ) ; v . add ( a [ i ] ) ; if ( i < n - 1 && a [ i ] < a [ i + 1 ] ) { while ( i < n - 1 && a [ i ] < a [ i + 1 ] ) { v . add ( a [ i + 1 ] ) ; i += 1 ; } } else if ( i < n - 1 && a [ i ] > a [ i + 1 ] ) { while ( i < n - 1 && a [ i ] > a [ i + 1 ] ) { v . add ( a [ i + 1 ] ) ; i += 1 ; } } int prod = maxSubarrayProduct ( v , v . size ( ) ) ; maxProd = Math . max ( maxProd , prod ) ; i ++ ; } return maxProd ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 10 , 8 , 1 , 100 , 101 } ; int N = arr . length ; System . out . print ( findMaxProduct ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int [ ] parent = new int [ 1000000 ] ; static int root ( int a ) { if ( a == parent [ a ] ) { return a ; } return parent [ a ] = root ( parent [ a ] ) ; } static void connect ( int a , int b ) { a = root ( a ) ; b = root ( b ) ; if ( a != b ) { parent [ b ] = a ; } } static void connectedComponents ( int n ) { HashSet < Integer > s = new HashSet < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { s . add ( parent [ i ] ) ; } System . out . println ( s . size ( ) ) ; } static void printAnswer ( int N , int [ ] [ ] edges ) { for ( int i = 0 ; i <= N ; i ++ ) { parent [ i ] = i ; } for ( int i = 0 ; i < edges . length ; i ++ ) { connect ( edges [ i ] [ 0 ] , edges [ i ] [ 1 ] ) ; } connectedComponents ( N ) ; } public static void main ( String [ ] args ) { int N = 8 ; int [ ] [ ] edges = { { 1 , 0 } , { 0 , 2 } , { 5 , 3 } , { 3 , 4 } , { 6 , 7 } } ; printAnswer ( N , edges ) ; } }

Index/key variables: a, b, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void removeZeroRowCol ( int arr [ ] [ ] ) { int n = arr . length ; int col [ ] = new int [ n + 1 ] ; int row [ ] = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) { int count = 0 ; for ( int j = 0 ; j < n ; ++ j ) { if ( arr [ i ] [ j ] == 1 ) col [ j ] += 1 ; else col [ j ] += 0 ; if ( arr [ i ] [ j ] == 1 ) count += 1 ; else count += 0 ; } row [ i ] = count ; } for ( int i = 0 ; i < n ; ++ i ) { if ( row [ i ] == 0 ) { continue ; } for ( int j = 0 ; j < n ; ++ j ) { if ( col [ j ] != 0 ) System . out . print ( arr [ i ] [ j ] ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 1 , 1 , 0 , 1 } , { 0 , 0 , 0 , 0 } , { 1 , 1 , 0 , 1 } , { 0 , 1 , 0 , 1 } } ; removeZeroRowCol ( arr ) ; } }

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class pair { int l , r , index ; pair ( int l , int r , int index ) { this . l = l ; this . r = r ; this . index = index ; } } class GFG { static void findOverlapSegement ( int N , int [ ] a , int [ ] b ) { ArrayList < pair > tup = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int x , y ; x = a [ i ] ; y = b [ i ] ; tup . add ( new pair ( x , y , i ) ) ; } Collections . sort ( tup , ( aa , bb ) -> ( aa . l != bb . l ) ? aa . l - bb . l : aa . r - bb . r ) ; int curr = tup . get ( 0 ) . r ; int currPos = tup . get ( 0 ) . index ; for ( int i = 1 ; i < N ; i ++ ) { int Q = tup . get ( i - 1 ) . l ; int R = tup . get ( i ) . l ; if ( Q == R ) { if ( tup . get ( i - 1 ) . r < tup . get ( i ) . r ) System . out . print ( tup . get ( i - 1 ) . index + " ▁ " + tup . get ( i ) . index ) ; else System . out . print ( tup . get ( i ) . index + " ▁ " + tup . get ( i - 1 ) . index ) ; return ; } int T = tup . get ( i ) . r ; if ( T <= curr ) { System . out . print ( tup . get ( i ) . index + " ▁ " + currPos ) ; return ; } else { curr = T ; currPos = tup . get ( i ) . index ; } } System . out . print ( " - 1 ▁ - 1" ) ; } public static void main ( String [ ] args ) { int [ ] a = { 1 , 2 , 3 , 2 , 2 } ; int [ ] b = { 5 , 10 , 10 , 2 , 15 } ; int N = a . length ; findOverlapSegement ( N , a , b ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . io . * ; import java . util . Arrays ; class GFG { public static int countDivBy3InArray ( int [ ] arr ) { int ans = 0 ; boolean [ ] taken = new boolean [ arr . length ] ; Arrays . fill ( taken , false ) ; for ( int i = 0 ; i < arr . length ; i ++ ) { if ( taken [ i ] == true ) { continue ; } for ( int j = i + 1 ; j < arr . length ; j ++ ) { if ( taken [ j ] == true ) { continue ; } if ( Integer . parseInt ( Integer . toString ( arr [ i ] ) + Integer . toString ( arr [ j ] ) ) % 3 == 0 || Integer . parseInt ( Integer . toString ( arr [ j ] ) + Integer . toString ( arr [ i ] ) ) % 3 == 0 ) { ans += 1 ; taken [ i ] = true ; taken [ j ] = true ; } } } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 5 , 3 , 2 , 8 , 7 } ; System . out . println ( countDivBy3InArray ( arr ) ) ; } }

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