dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; @ SuppressWarnings ( " unchecked " ) class GFG { static int MAX_SIZE = 100005 , MAX_CHAR = 26 ; static int [ ] [ ] nodeCharactersCount = new int [ MAX_SIZE ] [ MAX_CHAR ] ; static Vector < Integer > [ ] tree = new Vector [ MAX_SIZE ] ; static boolean canFormPalindrome ( int [ ] charArray ) { int oddCount = 0 ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { if ( charArray [ i ] % 2 == 1 ) oddCount ++ ; } if ( oddCount >= 2 ) return false ; else return true ; } static int LCA ( int currentNode , int x , int y ) { if ( currentNode == x ) return x ; if ( currentNode == y ) return y ; int xLca , yLca ; xLca = yLca = - 1 ; int gotLca = - 1 ; for ( int l = 0 ; l < tree [ currentNode ] . size ( ) ; l ++ ) { int nextNode = tree [ currentNode ] . elementAt ( l ) ; int out_ = LCA ( nextNode , x , y ) ; if ( out_ == x ) xLca = out_ ; if ( out_ == y ) yLca = out_ ; if ( xLca != - 1 && yLca != - 1 ) return currentNode ; if ( out_ != - 1 ) gotLca = out_ ; } return gotLca ; } static void buildTree ( int i ) { for ( int l = 0 ; l < tree [ i ] . size ( ) ; l ++ ) { int nextNode = tree [ i ] . elementAt ( l ) ; for ( int j = 0 ; j < MAX_CHAR ; j ++ ) { nodeCharactersCount [ nextNode ] [ j ] += nodeCharactersCount [ i ] [ j ] ; } buildTree ( nextNode ) ; } } static boolean canFormPalindromicPath ( int x , int y ) { int lcaNode ; if ( x == y ) lcaNode = x ; else lcaNode = LCA ( 1 , x , y ) ; int [ ] charactersCountFromXtoY = new int [ MAX_CHAR ] ; Arrays . fill ( charactersCountFromXtoY , 0 ) ; for ( int i = 0 ; i < MAX_CHAR ; i ++ ) { charactersCountFromXtoY [ i ] = nodeCharactersCount [ x ] [ i ] + nodeCharactersCount [ y ] [ i ] - 2 * nodeCharactersCount [ lcaNode ] [ i ] ; } if ( canFormPalindrome ( charactersCountFromXtoY ) ) return true ; return false ; } static void updateNodeCharactersCount ( String str , int v ) { for ( int i = 0 ; i < str . length ( ) ; i ++ ) nodeCharactersCount [ v ] [ str . charAt ( i ) - ' a ' ] ++ ; } static void performQueries ( int [ ] [ ] queries , int q ) { int i = 0 ; while ( i < q ) { int x = queries [ i ] [ 0 ] ; int y = queries [ i ] [ 1 ] ; if ( canFormPalindromicPath ( x , y ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; i ++ ; } } public static void main ( String [ ] args ) { for ( int i = 0 ; i < MAX_SIZE ; i ++ ) { for ( int j = 0 ; j < MAX_CHAR ; j ++ ) { nodeCharactersCount [ i ] [ j ] = 0 ; } } for ( int i = 0 ; i < MAX_SIZE ; i ++ ) { tree [ i ] = new Vector < > ( ) ; } tree [ 1 ] . add ( 2 ) ; updateNodeCharactersCount ( " bbc " , 2 ) ; tree [ 1 ] . add ( 3 ) ; updateNodeCharactersCount ( " ac " , 3 ) ; buildTree ( 1 ) ; int [ ] [ ] queries = { { 1 , 2 } , { 2 , 3 } , { 3 , 1 } , { 3 , 3 } } ; int q = queries . length ; performQueries ( queries , q ) ; } }

Index/key variables: MAX_CHAR, MAX_SIZE, currentNode, i, j, lcaNode, nextNode, v, x, y
Accumulator variables: i, j, l, oddCount
Iterator variables: i, j, l
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Node { Node left ; Node right ; int data ; } ; static Node newNode ( int key ) { Node node = new Node ( ) ; node . left = node . right = null ; node . data = key ; return node ; } static Vector < Integer > path ; static boolean FindPath ( Node root , int key ) { if ( root == null ) return false ; path . add ( root . data ) ; if ( root . data == key ) return true ; if ( FindPath ( root . left , key ) || FindPath ( root . right , key ) ) return true ; path . remove ( path . size ( ) - 1 ) ; return false ; } static int minMaxNodeInPath ( Node root , int a , int b ) { path = new Vector < Integer > ( ) ; boolean flag = true ; Vector < Integer > Path2 = new Vector < Integer > ( ) , Path1 = new Vector < Integer > ( ) ; int min1 = Integer . MAX_VALUE ; int max1 = Integer . MIN_VALUE ; int min2 = Integer . MAX_VALUE ; int max2 = Integer . MIN_VALUE ; int i = 0 ; int j = 0 ; flag = FindPath ( root , a ) ; Path1 = path ; path = new Vector < Integer > ( ) ; flag &= FindPath ( root , b ) ; Path2 = path ; if ( flag ) { for ( i = 0 ; i < Path1 . size ( ) && i < Path2 . size ( ) ; i ++ ) if ( Path1 . get ( i ) != Path2 . get ( i ) ) break ; i -- ; j = i ; for ( ; i < Path1 . size ( ) ; i ++ ) { if ( min1 > Path1 . get ( i ) ) min1 = Path1 . get ( i ) ; if ( max1 < Path1 . get ( i ) ) max1 = Path1 . get ( i ) ; } for ( ; j < Path2 . size ( ) ; j ++ ) { if ( min2 > Path2 . get ( j ) ) min2 = Path2 . get ( j ) ; if ( max2 < Path2 . get ( j ) ) max2 = Path2 . get ( j ) ; } System . out . println ( " Min ▁ = ▁ " + Math . min ( min1 , min2 ) ) ; System . out . println ( " Max ▁ = ▁ " + Math . max ( max1 , max2 ) ) ; } else System . out . println ( "Min = -1 Max = - 1 "); return 0 ; } public static void main ( String args [ ] ) { Node root = newNode ( 20 ) ; root . left = newNode ( 8 ) ; root . right = newNode ( 22 ) ; root . left . left = newNode ( 5 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 4 ) ; root . right . right = newNode ( 25 ) ; root . left . right . left = newNode ( 10 ) ; root . left . right . right = newNode ( 14 ) ; int a = 5 ; int b = 14 ; minMaxNodeInPath ( root , a , b ) ; } }

Accumulator variables: flag, i, j
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG, Node
Java program:
import java . util . * ; class solution { static class Node { int data ; Node left ; Node right ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return node ; } static boolean getPath ( Node root , Vector < Integer > arr , int x ) { if ( root == null ) return false ; arr . add ( root . data ) ; if ( root . data == x ) return true ; if ( getPath ( root . left , arr , x ) || getPath ( root . right , arr , x ) ) return true ; arr . remove ( arr . size ( ) - 1 ) ; return false ; } static int sumOddNodes ( Node root , int n1 , int n2 ) { Vector < Integer > path1 = new Vector < Integer > ( ) ; Vector < Integer > path2 = new Vector < Integer > ( ) ; getPath ( root , path1 , n1 ) ; getPath ( root , path2 , n2 ) ; int intersection = - 1 ; int i = 0 , j = 0 ; while ( i != path1 . size ( ) || j != path2 . size ( ) ) { if ( i == j && path1 . get ( i ) == path2 . get ( j ) ) { i ++ ; j ++ ; } else { intersection = j - 1 ; break ; } } int sum = 0 ; for ( i = path1 . size ( ) - 1 ; i > intersection ; i -- ) if ( path1 . get ( i ) % 2 != 0 ) sum += path1 . get ( i ) ; for ( i = intersection ; i < path2 . size ( ) ; i ++ ) if ( path2 . get ( i ) % 2 != 0 ) sum += path2 . get ( i ) ; return sum ; } public static void main ( String args [ ] ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; int node1 = 5 ; int node2 = 6 ; System . out . print ( sumOddNodes ( root , node1 , node2 ) ) ; } }

Accumulator variables: i, j, sum
Iterator variables: i
Class/struct names: Node, solution
Java program:
import java . util . * ; class GFG { static int MAX = 1000 ; static int findLCA ( int n1 , int n2 , int parent [ ] ) { boolean [ ] visited = new boolean [ MAX ] ; visited [ n1 ] = true ; while ( parent [ n1 ] != - 1 ) { visited [ n1 ] = true ; n1 = parent [ n1 ] ; } visited [ n1 ] = true ; while ( ! visited [ n2 ] ) n2 = parent [ n2 ] ; return n2 ; } static void insertAdj ( int parent [ ] , int i , int j ) { parent [ i ] = j ; } public static void main ( String [ ] args ) { int [ ] parent = new int [ MAX ] ; parent [ 20 ] = - 1 ; insertAdj ( parent , 8 , 20 ) ; insertAdj ( parent , 22 , 20 ) ; insertAdj ( parent , 4 , 8 ) ; insertAdj ( parent , 12 , 8 ) ; insertAdj ( parent , 10 , 12 ) ; insertAdj ( parent , 14 , 12 ) ; System . out . println ( findLCA ( 10 , 14 , parent ) ) ; } }

Index/key variables: MAX, i, n1, n2
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int MAXN = 100001 ; static Vector < Integer > [ ] tree = new Vector [ MAXN ] ; static int [ ] [ ] path = new int [ 3 ] [ MAXN ] ; static boolean flag ; static void dfs ( int cur , int prev , int pathNumber , int ptr , int node ) { for ( int i = 0 ; i < tree [ cur ] . size ( ) ; i ++ ) { if ( tree [ cur ] . get ( i ) != prev && ! flag ) { path [ pathNumber ] [ ptr ] = tree [ cur ] . get ( i ) ; if ( tree [ cur ] . get ( i ) == node ) { flag = true ; path [ pathNumber ] [ ptr + 1 ] = - 1 ; return ; } dfs ( tree [ cur ] . get ( i ) , cur , pathNumber , ptr + 1 , node ) ; } } } static int LCA ( int a , int b ) { if ( a == b ) return a ; path [ 1 ] [ 0 ] = path [ 2 ] [ 0 ] = 1 ; flag = false ; dfs ( 1 , 0 , 1 , 1 , a ) ; flag = false ; dfs ( 1 , 0 , 2 , 1 , b ) ; int i = 0 ; while ( i < MAXN && path [ 1 ] [ i ] == path [ 2 ] [ i ] ) i ++ ; return path [ 1 ] [ i - 1 ] ; } static void addEdge ( int a , int b ) { tree [ a ] . add ( b ) ; tree [ b ] . add ( a ) ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < MAXN ; i ++ ) tree [ i ] = new Vector < Integer > ( ) ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 2 , 4 ) ; addEdge ( 2 , 5 ) ; addEdge ( 2 , 6 ) ; addEdge ( 3 , 7 ) ; addEdge ( 3 , 8 ) ; System . out . print ( " LCA ( 4 , ▁ 7 ) ▁ = ▁ " + LCA ( 4 , 7 ) + "NEW_LINE"); System . out . print ( " LCA ( 4 , ▁ 6 ) ▁ = ▁ " + LCA ( 4 , 6 ) + "NEW_LINE"); } }

Index/key variables: MAXN, a, b, cur, i, pathNumber, ptr
Accumulator variables: i
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int MAXN = 100000 ; static final int level = 18 ; @ SuppressWarnings ( " unchecked " ) static Vector < Integer > [ ] tree = new Vector [ MAXN ] ; static int [ ] depth = new int [ MAXN ] ; static int [ ] [ ] parent = new int [ MAXN ] [ level ] ; static void dfs ( int cur , int prev ) { depth [ cur ] = depth [ prev ] + 1 ; parent [ cur ] [ 0 ] = prev ; for ( int i = 0 ; i < tree [ cur ] . size ( ) ; i ++ ) { if ( tree [ cur ] . get ( i ) != prev ) dfs ( tree [ cur ] . get ( i ) , cur ) ; } } static void precomputeSparseMatrix ( int n ) { for ( int i = 1 ; i < level ; i ++ ) { for ( int node = 1 ; node <= n ; node ++ ) { if ( parent [ node ] [ i - 1 ] != - 1 ) parent [ node ] [ i ] = parent [ parent [ node ] [ i - 1 ] ] [ i - 1 ] ; } } } static int lca ( int u , int v ) { if ( depth [ v ] < depth [ u ] ) { u = u + v ; v = u - v ; u = u - v ; } int diff = depth [ v ] - depth [ u ] ; for ( int i = 0 ; i < level ; i ++ ) if ( ( ( diff >> i ) & 1 ) == 1 ) v = parent [ v ] [ i ] ; if ( u == v ) return u ; for ( int i = level - 1 ; i >= 0 ; i -- ) if ( parent [ u ] [ i ] != parent [ v ] [ i ] ) { u = parent [ u ] [ i ] ; v = parent [ v ] [ i ] ; } return parent [ u ] [ 0 ] ; } static void addEdge ( int u , int v ) { tree [ u ] . add ( v ) ; tree [ v ] . add ( u ) ; } static void memset ( int value ) { for ( int i = 0 ; i < MAXN ; i ++ ) { for ( int j = 0 ; j < level ; j ++ ) { parent [ i ] [ j ] = - 1 ; } } } public static void main ( String [ ] args ) { memset ( - 1 ) ; for ( int i = 0 ; i < MAXN ; i ++ ) tree [ i ] = new Vector < Integer > ( ) ; int n = 8 ; addEdge ( 1 , 2 ) ; addEdge ( 1 , 3 ) ; addEdge ( 2 , 4 ) ; addEdge ( 2 , 5 ) ; addEdge ( 2 , 6 ) ; addEdge ( 3 , 7 ) ; addEdge ( 3 , 8 ) ; depth [ 0 ] = 0 ; dfs ( 1 , 0 ) ; precomputeSparseMatrix ( n ) ; System . out . print ( " LCA ( 4 , ▁ 7 ) ▁ = ▁ " + lca ( 4 , 7 ) + "NEW_LINE"); System . out . print ( " LCA ( 4 , ▁ 6 ) ▁ = ▁ " + lca ( 4 , 6 ) + "NEW_LINE"); } }

Index/key variables: MAXN, cur, i, j, level, node, prev, u, v
Accumulator variables: i, j, node
Iterator variables: i, j, node
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Query { int L , R ; Query ( int L , int R ) { this . L = L ; this . R = R ; } } ; static int LCE ( String str , int n , int L , int R ) { int length = 0 ; while ( R + length < n && str . charAt ( L + length ) == str . charAt ( R + length ) ) length ++ ; return ( length ) ; } static void LCEQueries ( String str , int n , Query q [ ] , int m ) { for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L ; int R = q [ i ] . R ; System . out . printf ( "LCE (%d, %d) = %dNEW_LINE", L, R, LCE ( str , n , L , R ) ) ; } return ; } public static void main ( String [ ] args ) { String str = " abbababba " ; int n = str . length ( ) ; Query q [ ] = new Query [ 3 ] ; q [ 0 ] = new Query ( 1 , 2 ) ; q [ 1 ] = new Query ( 1 , 6 ) ; q [ 2 ] = new Query ( 0 , 5 ) ; int m = q . length ; LCEQueries ( str , n , q , m ) ; } }

Index/key variables: i
Accumulator variables: i, length
Iterator variables: i
Class/struct names: GFG, Query
Java program:
import java . lang . * ; import java . util . * ; class GFG { static boolean findPair ( int a [ ] , int n , int z ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( i != j && a [ i ] + a [ j ] == z ) return true ; return false ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , - 2 , 1 , 0 , 5 } ; int z = 0 ; int n = a . length ; if ( findPair ( a , n , z ) ) System . out . println ( " True " ) ; else System . out . println ( " False " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . lang . * ; import java . util . * ; class GFG { static void print ( int a [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( i != j ) System . out . println ( a [ i ] + " ▁ " + a [ j ] ) ; } } } public static void main ( String [ ] args ) { int a [ ] = { 1 , 2 , 3 } ; int n = a . length ; print ( a , n ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int maximumSum ( int arr [ ] , int N ) { int Sum = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) Sum += ( arr [ i ] - arr [ i - 1 ] ) ; } return Sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 3 } ; int N = arr . length ; System . out . println ( maximumSum ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: Sum, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class Main { static int maxNumberOfXAddedUtil ( String str , char X ) { int countX = 0 ; int countNotX = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == X ) { countX ++ ; } else if ( countX < 3 ) { countNotX ++ ; countX = 0 ; } } if ( countX >= 3 ) return - 1 ; else return 2 * ( countNotX + 1 ) - ( str . length ( ) - countNotX ) ; } static void maxNumberOfXAdded ( String str , char X ) { int ans = maxNumberOfXAddedUtil ( str , X ) ; System . out . println ( ans ) ; } public static void main ( String [ ] args ) { String str = " xxyxy " ; char X = X ; maxNumberOfXAdded ( str , X ) ; } }

Accumulator variables: countNotX, countX, i
Iterator variables: i
Class/struct names: Main
Java program:
class GFG { public static void main ( String [ ] args ) { int a = 0 , b = 0 ; int N = 4 , M = 4 ; for ( int i = 0 ; i < N ; i ++ ) { a = a + 10 ; } for ( int i = 0 ; i < M ; i ++ ) { b = b + 40 ; } System . out . print ( a + " ▁ " + b ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void stoogesort ( int arr [ ] , int l , int h ) { if ( l >= h ) return ; if ( arr [ l ] > arr [ h ] ) { int temp = arr [ l ] ; arr [ l ] = arr [ h ] ; arr [ h ] = temp ; } if ( h - l + 1 > 2 ) { int t = ( h - l + 1 ) / 3 ; stoogesort ( arr , l , h - t ) ; stoogesort ( arr , l + t , h ) ; stoogesort ( arr , l , h - t ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 5 , 3 , 1 } ; int N = arr . length ; stoogesort ( arr , 0 , N - 1 ) ; for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } }

Index/key variables: h, i, l
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int Fibonacci ( int N ) { if ( N < 2 ) return N ; return Fibonacci ( N - 1 ) + Fibonacci ( N - 2 ) ; } public static void main ( String [ ] args ) { int N = 5 ; System . out . print ( Fibonacci ( N ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static void findWinner ( int n , int m ) { int X = 0 ; int Y = 0 ; if ( n >= m ) { X = n - 1 ; Y = m ; } else { X = m - 1 ; Y = n ; } if ( X > Y ) System . out . print ( " X " ) ; else if ( Y > X ) System . out . print ( " Y " ) ; else System . out . print ( " - 1" ) ; } public static void main ( String [ ] args ) { int n = 3 , m = 1 ; findWinner ( n , m ) ; } }

Class/struct names: GFG
Java program:
class GFG { static void checkPascaltriangle ( int N ) { double x = ( Math . sqrt ( 8 * N + 1 ) - 1 ) / 2 ; if ( Math . ceil ( x ) - x == 0 ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { int N = 10 ; checkPascaltriangle ( N ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void countSubarrays ( int arr [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; for ( int j = i ; j < n ; j ++ ) { if ( ( j - i ) % 2 == 0 ) sum += arr [ j ] ; else sum -= arr [ j ] ; if ( sum == 0 ) count ++ ; } } System . out . println ( count ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 6 , 4 , 2 } ; int n = arr . length ; countSubarrays ( arr , n ) ; } }

Index/key variables: j
Accumulator variables: count, i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Scanner ; public class P2Placerooks { static void findCountRooks ( int row [ ] , int col [ ] , int n , int k ) { int res = n - k ; System . out . println ( res + " ▁ " ) ; int ri = 0 , ci = 0 ; while ( res -- > 0 ) { while ( ri < k && row [ ri ] == 1 ) { ri ++ ; } while ( ci < k && col [ ci ] == 1 ) { ci ++ ; } System . out . println ( ( ri + 1 ) + " ▁ " + ( ci + 1 ) + " ▁ " ) ; ri ++ ; ci ++ ; } } public static void main ( String [ ] args ) { int n = 4 ; int k = 2 ; int row [ ] = { 1 , 2 } ; int col [ ] = { 4 , 2 } ; findCountRooks ( row , col , n , k ) ; } }

Index/key variables: ci, ri
Accumulator variables: ci, res, ri
Class/struct names: P2Placerooks
Java program:
class GFG { static boolean checkIfDivisible ( String str , long num ) { long powerOf2 = ( int ) ( Math . log ( num ) / Math . log ( 2 ) ) ; if ( str . length ( ) < powerOf2 ) return false ; if ( powerOf2 == 0 ) return true ; long i , number = 0 ; int len = str . length ( ) ; for ( i = len - powerOf2 ; i < len ; i ++ ) { number += ( str . charAt ( ( int ) i ) - '0' ) * Math . pow ( 10 , powerOf2 - 1 ) ; powerOf2 -- ; } if ( number % num != 0 ) return false ; else return true ; } public static void main ( String [ ] args ) { String str = "213467756564" ; long num = 4 ; if ( checkIfDivisible ( str , num ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }

Accumulator variables: i, number, powerOf2
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static boolean check_order ( int [ ] arr ) { int cnt = 0 ; for ( int i = 0 ; i < arr . length - 1 ; i ++ ) { if ( Math . abs ( arr [ i + 1 ] - arr [ i ] ) > 1 ) cnt ++ ; } if ( Math . abs ( arr [ 0 ] - arr [ arr . length - 1 ] ) > 1 ) cnt ++ ; if ( cnt > 1 ) return false ; return true ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 4 , 5 , 1 } ; if ( check_order ( arr ) ) System . out . print ( " YES " ) ; else System . out . print ( " NO " ) ; } }

Index/key variables: i
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int getM ( int n ) { if ( n == 1 ) return - 1 ; else return n - 2 ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . print ( getM ( n ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static int maxProfit ( int prices [ ] , int n ) { if ( n <= 1 ) return 0 ; int rest [ ] = new int [ n ] ; int hold [ ] = new int [ 9 ] ; int sold [ ] = new int [ 9 ] ; rest [ 0 ] = 0 ; hold [ 0 ] = - prices [ 0 ] ; sold [ 0 ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) { rest [ i ] = Math . max ( rest [ i - 1 ] , sold [ i - 1 ] ) ; hold [ i ] = Math . max ( hold [ i - 1 ] , rest [ i - 1 ] - prices [ i ] ) ; sold [ i ] = hold [ i - 1 ] + prices [ i ] ; } return Math . max ( rest [ n - 1 ] , sold [ n - 1 ] ) ; } public static void main ( String [ ] args ) { int price [ ] = { 2 , 4 , 5 , 0 , 2 } ; int n = price . length ; System . out . print ( maxProfit ( price , n ) + "NEW_LINE"); } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int findSubarrays ( int arr [ ] , int N , int K ) { return N - K + 1 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 5 , 3 , 2 , 17 , 18 } ; int K = 4 ; int N = arr . length ; System . out . print ( findSubarrays ( arr , N , K ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int longest_subarray ( int arr [ ] , int d ) { int i = 0 , j = 1 , e = 0 ; for ( i = 0 ; i < d - 1 ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { j = j + 1 ; } else { j = 1 ; } if ( e < j ) { e = j ; } } return e ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = arr . length ; System . out . print ( longest_subarray ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int [ ] factorial = { 1 , 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880 } ; public static boolean isStrong ( int N ) { String num = Integer . toString ( N ) ; int sum = 0 ; for ( int i = 0 ; i < num . length ( ) ; i ++ ) { sum += factorial [ Integer . parseInt ( num . charAt ( i ) + " " ) ] ; } return sum == N ; } public static void printStrongNumbers ( int N ) { for ( int i = 1 ; i <= N ; i ++ ) { if ( isStrong ( i ) ) { System . out . print ( i + " ▁ " ) ; } } } public static void main ( String [ ] args ) throws java . lang . Exception { int N = 1000 ; printStrongNumbers ( N ) ; } }

Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int countPairs ( int A , int B ) { int countY = 0 , countX = ( B - A ) + 1 , next_val = 9 ; while ( next_val <= B ) { if ( next_val >= A ) { countY += 1 ; } next_val = next_val * 10 + 9 ; } return ( countX * countY ) ; } public static void main ( String args [ ] ) { int A = 1 ; int B = 16 ; System . out . print ( countPairs ( A , B ) ) ; } }

Accumulator variables: countY
Class/struct names: GFG
Java program:
class GFG { public static int solve ( int n , int m ) { int ans = n * ( m / 2 ) ; if ( m % 2 == 1 ) { ans += ( n + 1 ) / 2 ; } return ans ; } public static void main ( String args [ ] ) { int N = 5 ; int M = 3 ; System . out . println ( solve ( N , M ) ) ; } }

Accumulator variables: ans
Class/struct names: GFG
Java program:
class GFG { static int max_len = 100005 ; static int cnt [ ] = new int [ max_len ] ; public static void precompute ( String s , String K ) { int n = s . length ( ) ; for ( int i = 0 ; i < n - 2 ; i ++ ) { cnt [ i + 1 ] = cnt [ i ] ; if ( s . substring ( i , i + K . length ( ) ) . equals ( K ) ) { cnt [ i + 1 ] += 1 ; } } cnt [ n - 2 + 1 ] = cnt [ n - 2 ] ; } public static void main ( String [ ] args ) { String s = " ABCABCABABC " ; String K = " ABC " ; precompute ( s , K ) ; int Q [ ] [ ] = { { 1 , 6 } , { 5 , 11 } } ; for ( int it = 0 ; it < Q . length ; it ++ ) { System . out . println ( cnt [ Q [ it ] [ 1 ] - 1 ] - cnt [ Q [ it ] [ 0 ] - 1 ] ) ; } } }

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