dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static final int MOD = 1000000007 ; static long modPower ( long x , int y ) { long res = 1 ; x = x % MOD ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % MOD ; y = y / 2 ; x = ( x * x ) % MOD ; } return res ; } static int countPairs ( long arr [ ] , int N ) { int pairCount = 0 ; HashMap < Long , Integer > hash = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( hash . containsKey ( arr [ i ] ) ) { hash . put ( arr [ i ] , hash . get ( arr [ i ] ) + 1 ) ; } else { hash . put ( arr [ i ] , 1 ) ; } } for ( int i = 0 ; i < N ; i ++ ) { long modularInverse = modPower ( arr [ i ] , MOD - 2 ) ; if ( hash . containsKey ( modularInverse ) ) pairCount += hash . get ( modularInverse ) ; if ( arr [ i ] == modularInverse ) { pairCount -- ; } } return pairCount / 2 ; } public static void main ( String [ ] args ) { long arr [ ] = { 2 , 236426 , 280311812 , 500000004 } ; int N = arr . length ; System . out . print ( countPairs ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i, pairCount
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static String check ( int arr [ ] , int n ) { Map < Integer , Integer > hm = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { hm . put ( arr [ i ] , 1 ) ; for ( int j = i + 1 ; j < n ; j ++ ) { hm . put ( arr [ j ] , hm . getOrDefault ( arr [ j ] , 0 ) + 1 ) ; boolean flag = false ; for ( Integer k : hm . values ( ) ) { if ( k == 1 ) { flag = true ; break ; } } if ( ! flag ) return " No " ; } hm . clear ( ) ; } return " Yes " ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 1 } ; int N = arr . length ; System . out . println ( check ( arr , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j, k
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int find_index ( int [ ] arr , int n , int K ) { int start = 0 ; int end = n - 1 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( arr [ mid ] == K ) return mid ; else if ( arr [ mid ] < K ) start = mid + 1 ; else end = mid - 1 ; } return end + 1 ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 5 , 6 } ; int n = arr . length ; int K = 2 ; System . out . println ( find_index ( arr , n , K ) ) ; } }

Index/key variables: mid
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int computePos ( int arr [ ] , int n , int value ) { if ( value < arr [ 0 ] ) return 0 ; if ( value > arr [ n - 1 ] ) return n - 1 ; int start = 0 ; int end = n - 1 ; while ( start < end ) { int mid = ( start + end + 1 ) / 2 ; if ( arr [ mid ] >= value ) end = mid - 1 ; else start = mid ; } return start ; } static void countShift ( int arr [ ] , int n , Vector < Vector < Integer > > queries ) { for ( Vector < Integer > q : queries ) { int index = q . get ( 0 ) ; int update = q . get ( 1 ) ; int newElement = arr [ index ] + update ; int newIndex = computePos ( arr , n , newElement ) ; System . out . print ( Math . abs ( newIndex - index ) + " ▁ " ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 5 , 6 } ; int N = arr . length ; Vector < Vector < Integer > > queries = new Vector < > ( ) ; Vector < Integer > v = new Vector < > ( ) ; Vector < Integer > v1 = new Vector < > ( ) ; v . add ( 0 ) ; v . add ( - 1 ) ; queries . add ( v ) ; v1 . add ( 4 ) ; v1 . add ( - 11 ) ; queries . add ( v1 ) ; countShift ( arr , N , queries ) ; } }

Index/key variables: index, mid
Iterator variables: q
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Node { int key ; Node left , right ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return temp ; } static int ans ; static void countReqNodes ( Node root , int minNodeVal ) { if ( root == null ) return ; if ( root . key <= minNodeVal ) { minNodeVal = root . key ; ans ++ ; } countReqNodes ( root . left , minNodeVal ) ; countReqNodes ( root . right , minNodeVal ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 8 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 6 ) ; root . left . right = newNode ( 7 ) ; root . right . left = newNode ( 3 ) ; root . right . right = newNode ( 9 ) ; int minNodeVal = Integer . MAX_VALUE ; ans = 0 ; countReqNodes ( root , minNodeVal ) ; System . out . print ( ans ) ; } }

Accumulator variables: ans
Class/struct names: GFG, Node
Java program:
import java . io . * ; import java . util . * ; class GFG { static boolean isPalindrome ( String str ) { int i = 0 , j = str . length ( ) - 1 ; while ( i < j ) { if ( str . charAt ( i ) != str . charAt ( j ) ) return false ; i ++ ; j -- ; } return true ; } static void formPalindrome ( String a , String b , int n ) { char aa [ ] = new char [ n + 2 ] ; char bb [ ] = new char [ n + 2 ] ; Arrays . fill ( aa , ' ▁ ' ) ; Arrays . fill ( bb , ' ▁ ' ) ; for ( int i = 1 ; i <= n ; i ++ ) { aa [ i ] = a . charAt ( i - 1 ) ; bb [ i ] = b . charAt ( i - 1 ) ; } boolean ok = false ; for ( int i = 0 ; i <= n + 1 ; i ++ ) { StringBuilder la = new StringBuilder ( ) ; StringBuilder ra = new StringBuilder ( ) ; StringBuilder lb = new StringBuilder ( ) ; StringBuilder rb = new StringBuilder ( ) ; for ( int j = 1 ; j <= i - 1 ; j ++ ) { la . append ( ( aa [ j ] == ' ▁ ' ) ? " " : aa [ j ] ) ; lb . append ( ( bb [ j ] == ' ▁ ' ) ? " " : bb [ j ] ) ; } for ( int j = i ; j <= n + 1 ; j ++ ) { ra . append ( ( aa [ j ] == ' ▁ ' ) ? " " : aa [ j ] ) ; rb . append ( ( bb [ j ] == ' ▁ ' ) ? " " : bb [ j ] ) ; } if ( isPalindrome ( la . toString ( ) + rb . toString ( ) ) || isPalindrome ( lb . toString ( ) + ra . toString ( ) ) ) { ok = true ; break ; } } if ( ok ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String A = " bdea " ; String B = " abbb " ; int N = 4 ; formPalindrome ( A , B , N ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: ok
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static int minElements ( int [ ] A , int [ ] B , int N , int M ) { Map < Integer , Integer > map = new HashMap < > ( ) ; for ( int i = 0 ; i < A . length ; i ++ ) { map . put ( A [ i ] , i ) ; } ArrayList < Integer > subseq = new ArrayList < > ( ) ; int l = 0 , r = - 1 ; for ( int i = 0 ; i < M ; i ++ ) { if ( map . containsKey ( B [ i ] ) ) { int e = map . get ( B [ i ] ) ; while ( l <= r ) { int m = l + ( r - l ) / 2 ; if ( subseq . get ( m ) < e ) l = m + 1 ; else r = m - 1 ; } if ( r + 1 < subseq . size ( ) ) { subseq . set ( r + 1 , e ) ; } else { subseq . add ( e ) ; } l = 0 ; r = subseq . size ( ) - 1 ; } } return N - subseq . size ( ) ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 2 , 3 , 4 , 5 } ; int [ ] B = { 2 , 5 , 6 , 4 , 9 , 12 } ; int M = A . length ; int N = B . length ; System . out . println ( minElements ( A , B , M , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static boolean sfpa ( int V , int src , int Edges [ ] [ ] , int M ) { Vector < pair > [ ] g = new Vector [ V ] ; for ( int i = 0 ; i < V ; i ++ ) { g [ i ] = new Vector < pair > ( ) ; } for ( int i = 0 ; i < M ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; int w = Edges [ i ] [ 2 ] ; g [ u ] . add ( new pair ( v , w ) ) ; } int [ ] dist = new int [ V ] ; Arrays . fill ( dist , Integer . MAX_VALUE ) ; boolean [ ] inQueue = new boolean [ V ] ; int [ ] cnt = new int [ V ] ; dist [ src ] = 0 ; Queue < Integer > q = new LinkedList < > ( ) ; q . add ( src ) ; inQueue [ src ] = true ; while ( ! q . isEmpty ( ) ) { int u = q . peek ( ) ; q . remove ( ) ; inQueue [ u ] = false ; for ( pair x : g [ u ] ) { int v = x . first ; int cost = x . second ; if ( dist [ v ] > dist [ u ] + cost ) { dist [ v ] = dist [ u ] + cost ; if ( ! inQueue [ v ] ) { q . add ( v ) ; inQueue [ v ] = true ; cnt [ v ] ++ ; if ( cnt [ v ] >= V ) return true ; } } } } return false ; } public static void main ( String [ ] args ) { int N = 4 ; int src = 0 ; int M = 4 ; int Edges [ ] [ ] = { { 0 , 1 , 1 } , { 1 , 2 , - 1 } , { 2 , 3 , - 1 } , { 3 , 0 , - 1 } } ; if ( sfpa ( N , src , Edges , M ) == true ) System . out . print ( " Yes " + "NEW_LINE"); else System . out . print ( " No " + "NEW_LINE"); } }

Index/key variables: V, i, src, u, v
Accumulator variables: i
Iterator variables: i, x
Class/struct names: GFG, pair
Java program:
class GFG { static final int INF = 99999 ; static int floyd_warshall ( int [ ] [ ] graph , int V ) { int [ ] [ ] dist = new int [ V ] [ V ] ; int i , j , k ; for ( i = 0 ; i < V ; i ++ ) { for ( j = 0 ; j < V ; j ++ ) { dist [ i ] [ j ] = graph [ i ] [ j ] ; } } for ( k = 0 ; k < V ; k ++ ) { for ( i = 0 ; i < V ; i ++ ) { for ( j = 0 ; j < V ; j ++ ) { if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) { dist [ i ] [ j ] = dist [ i ] [ k ] + dist [ k ] [ j ] ; } } } } int sum = 0 ; for ( i = 0 ; i < V ; i ++ ) { for ( j = i + 1 ; j < V ; j ++ ) { sum += dist [ i ] [ j ] ; } } return sum ; } static int sumOfshortestPath ( int N , int E , int edges [ ] [ ] ) { int [ ] [ ] g = new int [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { g [ i ] [ j ] = INF ; } } for ( int i = 0 ; i < E ; i ++ ) { int u = edges [ i ] [ 0 ] ; int v = edges [ i ] [ 1 ] ; int w = edges [ i ] [ 2 ] ; g [ u ] [ v ] = w ; g [ v ] [ u ] = w ; } return floyd_warshall ( g , N ) ; } public static void main ( String [ ] args ) { int N = 4 ; int E = 3 ; int Edges [ ] [ ] = { { 0 , 1 , 1 } , { 1 , 2 , 2 } , { 2 , 3 , 3 } } ; System . out . print ( sumOfshortestPath ( N , E , Edges ) ) ; } }

Index/key variables: N, V, i, j, k, u, v
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void print_kth_string ( String s , int K ) { int N = s . length ( ) ; int i ; for ( i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' ▁ ' ) K -- ; if ( K == 1 ) break ; } while ( i ++ < N - 1 && s . charAt ( i ) != ' ▁ ' ) System . out . print ( s . charAt ( i ) ) ; } public static void main ( String [ ] args ) { String s = "10 ▁ 20 ▁ 30 ▁ 40" ; int K = 4 ; print_kth_string ( s , K ) ; } }

Accumulator variables: K, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void minPeaks ( ArrayList < Integer > list ) { int n = list . size ( ) ; ArrayList < Integer > result = new ArrayList < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int min = Integer . MAX_VALUE ; int index = - 1 ; int size = list . size ( ) ; for ( int j = 0 ; j < size ; j ++ ) { if ( j == 0 && j + 1 < size ) { if ( list . get ( j ) > list . get ( j + 1 ) && min > list . get ( j ) ) { min = list . get ( j ) ; index = j ; } } else if ( j == size - 1 && j - 1 >= 0 ) { if ( list . get ( j ) > list . get ( j - 1 ) && min > list . get ( j ) ) { min = list . get ( j ) ; index = j ; } } else if ( size == 1 ) { min = list . get ( j ) ; index = j ; } else if ( list . get ( j ) > list . get ( j - 1 ) && list . get ( j ) > list . get ( j + 1 ) && min > list . get ( j ) ) { min = list . get ( j ) ; index = j ; } } list . remove ( index ) ; result . add ( min ) ; } System . out . println ( result ) ; } public static void main ( String [ ] args ) { ArrayList < Integer > arr = new ArrayList < > ( Arrays . asList ( 1 , 9 , 7 , 8 , 2 , 6 ) ) ; minPeaks ( arr ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int binarySearch ( int arr [ ] , int N , int X ) { int start = 0 ; int end = N ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; if ( X == arr [ mid ] ) { return mid ; } else if ( X < arr [ mid ] ) { start = mid + 1 ; } else { end = mid - 1 ; } } return - 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 4 , 3 , 2 , 1 } ; int N = arr . length ; int X = 5 ; System . out . println ( binarySearch ( arr , N , X ) ) ; } }

Index/key variables: mid
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static boolean check_both_present ( int [ ] arr , int N , int a , int b ) { boolean f1 = false , f2 = false ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == a ) { f1 = true ; } if ( arr [ i ] == b ) { f2 = true ; } } if ( f1 && f2 ) { return true ; } else { return false ; } } public static void print_array ( int [ ] ans , int N ) { for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( ans [ i ] + " ▁ " ) ; } } public static void build_AP ( int N , int a , int b ) { int [ ] arr = new int [ N ] ; int [ ] ans = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) ans [ i ] = Integer . MAX_VALUE ; int flag = 0 ; if ( a > b ) { a += ( b - ( b = a ) ) ; } int diff = b - a ; for ( int start = 1 ; start <= a ; start ++ ) { for ( int d = 1 ; d <= diff ; d ++ ) { arr [ 0 ] = start ; for ( int i = 1 ; i < N ; i ++ ) { arr [ i ] = arr [ i - 1 ] + d ; } if ( check_both_present ( arr , N , a , b ) && arr [ N - 1 ] < ans [ N - 1 ] ) { for ( int i = 0 ; i < N ; i ++ ) { ans [ i ] = arr [ i ] ; } } } } print_array ( ans , N ) ; } public static void main ( String [ ] args ) { int N = 5 , A = 20 , B = 50 ; build_AP ( N , A , B ) ; } }

Index/key variables: N, i
Accumulator variables: a, d, i, start
Iterator variables: d, i, start
Boolean variables: f1, f2
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; import java . lang . Math ; class GFG { static String isPrefixOfWord ( String sentence , String Word ) { String a [ ] = sentence . split ( " ▁ " ) ; ArrayList < String > v = new ArrayList < > ( ) ; for ( String e : a ) v . add ( e ) ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { for ( int j = 0 ; j < v . get ( i ) . length ( ) ; j ++ ) { if ( v . get ( i ) . charAt ( j ) != Word . charAt ( j ) ) break ; else if ( j == Word . length ( ) - 1 ) return v . get ( i ) ; } } return " - 1" ; } public static void main ( final String [ ] args ) { String s = " Welcome ▁ to ▁ Geeksforgeeks " ; String word = " Gee " ; System . out . println ( isPrefixOfWord ( s , word ) ) ; } }

Accumulator variables: i, j
Iterator variables: e, i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static class Pair { int idx ; String psf ; int jmps ; Pair ( int idx , String psf , int jmps ) { this . idx = idx ; this . psf = psf ; this . jmps = jmps ; } } public static int [ ] minJumps ( int [ ] arr ) { int dp [ ] = new int [ arr . length ] ; Arrays . fill ( dp , Integer . MAX_VALUE ) ; int n = dp . length ; dp [ n - 1 ] = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { int steps = arr [ i ] ; int min = Integer . MAX_VALUE ; for ( int j = 1 ; j <= steps && i + j < n ; j ++ ) { if ( dp [ i + j ] != Integer . MAX_VALUE && dp [ i + j ] < min ) { min = dp [ i + j ] ; } } if ( min != Integer . MAX_VALUE ) dp [ i ] = min + 1 ; } return dp ; } public static void possiblePath ( int [ ] arr , int [ ] dp ) { Queue < Pair > queue = new LinkedList < > ( ) ; queue . add ( new Pair ( 0 , " " + 0 , dp [ 0 ] ) ) ; while ( queue . size ( ) > 0 ) { Pair tmp = queue . remove ( ) ; if ( tmp . jmps == 0 ) { System . out . println ( tmp . psf ) ; continue ; } for ( int step = 1 ; step <= arr [ tmp . idx ] ; step ++ ) { if ( tmp . idx + step < arr . length && tmp . jmps - 1 == dp [ tmp . idx + step ] ) { queue . add ( new Pair ( tmp . idx + step , tmp . psf + " ▁ - > ▁ " + ( tmp . idx + step ) , tmp . jmps - 1 ) ) ; } } } } public static void Solution ( int arr [ ] ) { int dp [ ] = minJumps ( arr ) ; possiblePath ( arr , dp ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 3 , 0 , 2 , 1 , 2 , 4 , 2 , 0 , 0 } ; int size = arr . length ; Solution ( arr ) ; } }

Index/key variables: i
Accumulator variables: i, j, step
Iterator variables: i, j, step
Class/struct names: GFG, Pair
Java program:
import java . util . * ; import java . io . * ; class GFG { static void EvenLIS ( int arr [ ] ) { int n = arr . length ; int lis [ ] = new int [ n ] ; Arrays . fill ( lis , 1 ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( Math . abs ( arr [ i ] ) > Math . abs ( arr [ j ] ) && Math . abs ( arr [ i ] ) % 2 == 0 && Math . abs ( arr [ j ] ) % 2 == 0 && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; } } int maxlen = 0 ; for ( int i = 0 ; i < n ; i ++ ) maxlen = Math . max ( maxlen , lis [ i ] ) ; System . out . println ( maxlen ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 11 , - 22 , 43 , - 54 , 66 , 5 } ; int N = arr . length ; EvenLIS ( arr ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int res = 0 ; static class Node { int data ; Node left ; Node right ; Node ( int val ) { data = val ; left = right = null ; } } ; static int Sum ( Node root ) { if ( root == null ) { return 0 ; } int leftSubSum = Sum ( root . left ) ; int rightSubSum = Sum ( root . right ) ; if ( root . left != null && root . right != null && leftSubSum == rightSubSum ) res += 1 ; return root . data + leftSubSum + rightSubSum ; } public static void main ( String [ ] args ) { Node root = new Node ( 9 ) ; root . left = new Node ( 2 ) ; root . left . left = new Node ( - 1 ) ; root . left . right = new Node ( 3 ) ; root . right = new Node ( 4 ) ; root . right . right = new Node ( 0 ) ; res = 0 ; Sum ( root ) ; System . out . print ( res ) ; } }

Accumulator variables: res
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left ; Node right ; Node ( int val ) { data = val ; left = right = null ; } } ; static void PrintAlternate ( Node root ) { Queue < Node > Q = new LinkedList < > ( ) ; Q . add ( root ) ; while ( ! Q . isEmpty ( ) ) { int N = Q . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Node temp = Q . peek ( ) ; Q . remove ( ) ; if ( i % 2 == 0 ) { System . out . print ( temp . data + " ▁ " ) ; } if ( temp . left != null ) { Q . add ( temp . left ) ; } if ( temp . right != null ) { Q . add ( temp . right ) ; } } System . out . println ( ) ; } } public static void main ( String [ ] args ) { Node root ; root = new Node ( 71 ) ; root . left = new Node ( 88 ) ; root . right = new Node ( 99 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 9 ) ; root . left . right . left = new Node ( 10 ) ; root . left . right . right = new Node ( 11 ) ; root . right . left . right = new Node ( 13 ) ; root . right . right . left = new Node ( 14 ) ; PrintAlternate ( root ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
Java program:
import java . util . * ; public class gfg { static int [ ] countingSubarray ( int arr [ ] , int n ) { int a [ ] = new int [ n ] ; int nsml [ ] = new int [ n ] ; Arrays . fill ( nsml , - 1 ) ; int nsmr [ ] = new int [ n ] ; Arrays . fill ( nsmr , n ) ; Stack < Integer > st = new Stack < Integer > ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { while ( st . size ( ) > 0 && arr [ ( int ) st . peek ( ) ] >= arr [ i ] ) st . pop ( ) ; nsmr [ i ] = ( st . size ( ) > 0 ) ? ( int ) st . peek ( ) : n ; st . push ( i ) ; } while ( st . size ( ) > 0 ) st . pop ( ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( st . size ( ) > 0 && arr [ ( int ) st . peek ( ) ] >= arr [ i ] ) st . pop ( ) ; nsml [ i ] = ( st . size ( ) > 0 ) ? ( int ) st . peek ( ) : - 1 ; st . push ( i ) ; } for ( int i = 0 ; i < n ; i ++ ) { nsml [ i ] ++ ; nsmr [ i ] -- ; int r = nsmr [ i ] - i + 1 ; int l = i - nsml [ i ] + 1 ; a [ i ] = r * l ; } return a ; } public static void main ( String [ ] args ) { int N = 5 ; int arr [ ] = { 3 , 2 , 4 , 1 , 5 } ; int a [ ] = countingSubarray ( arr , N ) ; System . out . print ( " [ " ) ; int n = a . length - 1 ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( a [ i ] + " , ▁ " ) ; System . out . print ( a [ n ] + " ] " ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: gfg
Java program:
class GFG { static String reorderString ( char [ ] A , char [ ] B ) { int size_a = A . length ; int size_b = B . length ; int freq [ ] = new int [ 300 ] ; for ( int i = 0 ; i < size_b ; i ++ ) freq [ B [ i ] ] ++ ; for ( int i = 0 ; i < size_a ; i ++ ) freq [ A [ i ] ] -- ; for ( int j = ' a ' ; j <= ' z ' ; j ++ ) { if ( freq [ j ] < 0 ) return " - 1" ; } String answer = " " ; for ( int j = ' a ' ; j < A [ 0 ] ; j ++ ) while ( freq [ j ] > 0 ) { answer += j ; freq [ j ] -- ; } int first = A [ 0 ] ; for ( int j = 0 ; j < size_a ; j ++ ) { if ( A [ j ] > A [ 0 ] ) break ; if ( A [ j ] < A [ 0 ] ) { answer += String . valueOf ( A ) ; A = new char [ A . length ] ; break ; } } while ( freq [ first ] > 0 ) { answer += String . valueOf ( ( char ) first ) ; -- freq [ first ] ; } answer += String . valueOf ( A ) ; for ( int j = ' a ' ; j <= ' z ' ; j ++ ) while ( freq [ j ] -- > 0 ) answer += ( ( char ) j ) ; return answer ; } public static void main ( String [ ] args ) { String A = " aa " ; String B = " ababab " ; System . out . print ( reorderString ( A . toCharArray ( ) , B . toCharArray ( ) ) ) ; } }

Index/key variables: first, i, j
Accumulator variables: answer, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void maxConcurrentMeetingSlot ( int [ ] [ ] meetings ) { Arrays . sort ( meetings , ( a , b ) -> ( a [ 0 ] != b [ 0 ] ) ? a [ 0 ] - b [ 0 ] : a [ 1 ] - b [ 1 ] ) ; PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ; pq . add ( meetings [ 0 ] [ 1 ] ) ; int max_len = 0 , max_start = 0 ; int max_end = 0 ; for ( int [ ] k : meetings ) { while ( ! pq . isEmpty ( ) && k [ 0 ] >= pq . peek ( ) ) pq . poll ( ) ; pq . add ( k [ 1 ] ) ; if ( pq . size ( ) > max_len ) { max_len = pq . size ( ) ; max_start = k [ 0 ] ; max_end = pq . peek ( ) ; } } System . out . println ( max_start + " ▁ " + max_end ) ; } public static void main ( String [ ] args ) { int meetings [ ] [ ] = { { 100 , 200 } , { 50 , 300 } , { 300 , 400 } } ; maxConcurrentMeetingSlot ( meetings ) ; } }

Iterator variables: k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int func ( int n ) { int count = 0 ; if ( n == 2 n == 1 ) return 1 ; if ( n % 2 == 0 ) count = 1 + func ( n / 2 ) ; if ( n % 2 != 0 ) count = 1 + func ( n * 3 + 1 ) ; return count ; } static void findKthElement ( int l , int r , int k ) { ArrayList < Integer > arr = new ArrayList < > ( ) ; for ( int i = l ; i <= r ; i ++ ) arr . add ( i ) ; ArrayList < List < Integer > > result = new ArrayList < > ( ) ; for ( int i : arr ) result . add ( Arrays . asList ( i , func ( i ) ) ) ; Collections . sort ( result , ( s1 , s2 ) -> s1 . get ( 1 ) - s2 . get ( 1 ) ) ; System . out . println ( result . get ( k - 1 ) . get ( 0 ) ) ; } public static void main ( String [ ] args ) { int l = 12 ; int r = 15 ; int k = 2 ; findKthElement ( l , r , k ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { public static void checkHex ( String s ) { int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { char ch = s . charAt ( i ) ; if ( ( ch < '0' ch > '9' ) && ( ch < ' A ' ch > ' F ' ) ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } public static void main ( String [ ] args ) { String s = " BF57C " ; checkHex ( s ) ; } }

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