dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static int dp [ ] [ ] [ ] = new int [ 50 ] [ 10 ] [ 10 ] ; static void initialize ( ) { for ( int i = 0 ; i < 50 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { for ( int k = 0 ; k < 10 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } } static int countOfNumbers ( int digit , int prev1 , int prev2 , int N ) { if ( digit == N + 1 ) return 1 ; if ( dp [ digit ] [ prev1 ] [ prev2 ] != - 1 ) return dp [ digit ] [ prev1 ] [ prev2 ] ; dp [ digit ] [ prev1 ] [ prev2 ] = 0 ; if ( digit == 1 ) { for ( int j = ( N == 1 ? 0 : 1 ) ; j <= 9 ; ++ j ) { dp [ digit ] [ prev1 ] [ prev2 ] += countOfNumbers ( digit + 1 , j , prev1 , N ) ; } } else if ( digit == 2 ) { for ( int j = 0 ; j <= 9 ; ++ j ) { dp [ digit ] [ prev1 ] [ prev2 ] += countOfNumbers ( digit + 1 , j , prev1 , N ) ; } } else { for ( int j = 0 ; j <= Math . abs ( prev1 - prev2 ) ; ++ j ) { dp [ digit ] [ prev1 ] [ prev2 ] += countOfNumbers ( digit + 1 , j , prev1 , N ) ; } } return dp [ digit ] [ prev1 ] [ prev2 ] ; } public static void main ( String [ ] args ) { initialize ( ) ; int N = 3 ; System . out . print ( countOfNumbers ( 1 , 0 , 0 , N ) ) ; } }

Index/key variables: digit, i, j, k, prev1, prev2
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int count0 ( String s ) { int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) == '0' ) { count ++ ; } } return count ; } static int solve ( String [ ] vec , int A , int B , int idx , int dp [ ] [ ] [ ] ) { if ( idx == vec . length A + B == 0 ) { return 0 ; } if ( dp [ A ] [ B ] [ idx ] > 0 ) { return dp [ A ] [ B ] [ idx ] ; } int zero = count0 ( vec [ idx ] ) ; int one = vec [ idx ] . length ( ) - zero ; int inc = 0 ; if ( zero <= A && one <= B ) { inc = 1 + solve ( vec , A - zero , B - one , idx + 1 , dp ) ; } int exc = solve ( vec , A , B , idx + 1 , dp ) ; dp [ A ] [ B ] [ idx ] = Math . max ( inc , exc ) ; return dp [ A ] [ B ] [ idx ] ; } static int MaxSubsetlength ( String [ ] arr , int A , int B ) { int dp [ ] [ ] [ ] = new int [ A + 1 ] [ B + 1 ] [ arr . length + 1 ] ; return solve ( arr , A , B , 0 , dp ) ; } public static void main ( String [ ] args ) { String arr [ ] = { "1" , "0" , "10" } ; int A = 1 , B = 1 ; System . out . println ( MaxSubsetlength ( arr , A , B ) ) ; } }

Index/key variables: A, B, idx
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static boolean isMatch ( String text , String pattern ) { if ( text == null pattern == null ) { return false ; } int N = text . length ( ) ; int M = pattern . length ( ) ; boolean [ ] [ ] dp = new boolean [ N + 1 ] [ M + 1 ] ; dp [ 0 ] [ 0 ] = true ; for ( int i = 0 ; i < M ; i ++ ) { if ( pattern . charAt ( i ) == ' * ' && dp [ 0 ] [ i - 1 ] ) { dp [ 0 ] [ i + 1 ] = true ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( pattern . charAt ( j ) == ' . ' ) { dp [ i + 1 ] [ j + 1 ] = dp [ i ] [ j ] ; } if ( pattern . charAt ( j ) == text . charAt ( i ) ) { dp [ i + 1 ] [ j + 1 ] = dp [ i ] [ j ] ; } if ( pattern . charAt ( j ) == ' * ' ) { if ( pattern . charAt ( j - 1 ) != text . charAt ( i ) && pattern . charAt ( j - 1 ) != ' . ' ) { dp [ i + 1 ] [ j + 1 ] = dp [ i + 1 ] [ j - 1 ] ; } else { dp [ i + 1 ] [ j + 1 ] = ( dp [ i + 1 ] [ j ] dp [ i ] [ j + 1 ] dp [ i + 1 ] [ j - 1 ] ) ; } } } } return dp [ N ] [ M ] ; } public static void main ( String [ ] args ) { String text = " geeksforgeeks " ; String pattern = " ge * ksforgeeks " ; if ( isMatch ( text , pattern ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

Index/key variables: M, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void waysToPaint ( int n ) { long same = 6 ; long diff = 6 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { long sameTmp = 3 * same + 2 * diff ; long diffTmp = 2 * same + 2 * diff ; same = sameTmp ; diff = diffTmp ; } System . out . println ( same + diff ) ; } public static void main ( String [ ] args ) { int N = 2 ; waysToPaint ( N ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class Solution { int k ; int n ; int goal ; int dp [ ] [ ] ; List < Integer > bits = new ArrayList < > ( ) ; public int minimumIncompatibility ( int [ ] A , int k ) { this . n = A . length ; this . k = k ; goal = n / k ; Map < Integer , Integer > map = new HashMap < > ( ) ; for ( int i : A ) { if ( ! map . containsKey ( i ) ) map . put ( i , 0 ) ; map . put ( i , map . get ( i ) + 1 ) ; if ( map . get ( i ) > k ) return - 1 ; } int state = ( 1 << n ) - 1 ; for ( int i = 0 ; i <= state ; i ++ ) { if ( Integer . bitCount ( i ) == goal ) bits . add ( i ) ; } dp = new int [ 1 << n ] [ k ] ; for ( int i = 0 ; i < dp . length ; i ++ ) { Arrays . fill ( dp [ i ] , - 1 ) ; } return dfs ( A , state , 0 ) ; } public int dfs ( int A [ ] , int state , int index ) { if ( index >= k ) { return 0 ; } int res = 1000 ; if ( dp [ state ] [ index ] != - 1 ) { return dp [ state ] [ index ] ; } for ( int bit : bits ) { if ( Integer . bitCount ( bit ) == goal ) { int newstate = state ; int mn = 100 , mx = - 1 ; boolean visit [ ] = new boolean [ n + 1 ] ; boolean good = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( bit & ( 1 << j ) ) != 0 ) { if ( visit [ A [ j ] ] == true || ( state & ( 1 << j ) ) == 0 ) { good = false ; break ; } visit [ A [ j ] ] = true ; newstate = newstate ^ ( 1 << j ) ; mx = Math . max ( mx , A [ j ] ) ; mn = Math . min ( mn , A [ j ] ) ; } } if ( good ) { res = Math . min ( res , mx - mn + dfs ( A , newstate , index + 1 ) ) ; } } } dp [ state ] [ index ] = res ; return res ; } } class GFG { public static void main ( String [ ] args ) { Solution st = new Solution ( ) ; int [ ] arr = { 1 , 2 , 1 , 4 } ; int K = 2 ; System . out . print ( st . minimumIncompatibility ( arr , K ) ) ; } }

Index/key variables: i, index, j, k, state
Accumulator variables: i, j
Iterator variables: bit, i, j
Boolean variables: good
Class/struct names: GFG, Solution
Java program:
class GFG { static int FindMaxS ( int X , int Y , int Z , int n , int A [ ] , int B [ ] , int C [ ] ) { if ( X < 0 Y < 0 Z < 0 ) return Integer . MIN_VALUE ; if ( n < 0 ) return 0 ; int ch = A [ n ] + FindMaxS ( X - 1 , Y , Z , n - 1 , A , B , C ) ; int ca = B [ n ] + FindMaxS ( X , Y - 1 , Z , n - 1 , A , B , C ) ; int co = C [ n ] + FindMaxS ( X , Y , Z - 1 , n - 1 , A , B , C ) ; int no = FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ; int maximum = Math . max ( ch , Math . max ( ca , Math . max ( co , no ) ) ) ; return maximum ; } public static void main ( String [ ] args ) { int X = 1 ; int Y = 1 ; int Z = 1 ; int A [ ] = { 10 , 0 , 5 } ; int B [ ] = { 5 , 10 , 0 } ; int C [ ] = { 0 , 5 , 10 } ; int n = B . length ; System . out . println ( FindMaxS ( X , Y , Z , n - 1 , A , B , C ) ) ; } }

Index/key variables: n
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void replace ( int [ ] arr ) { int n = arr . length ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] >= 0 && arr [ j ] >= 0 && arr [ i ] % 2 == 0 && arr [ j ] % 2 != 0 ) { int tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; arr [ j ] = - arr [ j ] ; break ; } else if ( arr [ i ] >= 0 && arr [ j ] >= 0 && arr [ i ] % 2 != 0 && arr [ j ] % 2 == 0 ) { int tmp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = tmp ; arr [ j ] = - arr [ j ] ; break ; } } } for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = Math . abs ( arr [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 2 , 4 } ; replace ( arr ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GfG { static class Node { int data ; Node left , right ; } static int gethalfCount ( Node root ) { if ( root == null ) return 0 ; int res = 0 ; if ( ( root . left == null && root . right != null ) || ( root . left != null && root . right == null ) ) res ++ ; res += ( gethalfCount ( root . left ) + gethalfCount ( root . right ) ) ; return res ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 2 ) ; root . left = newNode ( 7 ) ; root . right = newNode ( 5 ) ; root . left . right = newNode ( 6 ) ; root . left . right . left = newNode ( 1 ) ; root . left . right . right = newNode ( 11 ) ; root . right . right = newNode ( 9 ) ; root . right . right . left = newNode ( 4 ) ; System . out . println ( gethalfCount ( root ) ) ; } }

Accumulator variables: res
Class/struct names: GfG, Node
Java program:
import java . util . * ; class GFG { static int minimumCostToMergeK ( int arr [ ] , int K , int N ) { if ( ( N - 1 ) % ( K - 1 ) != 0 ) { return - 1 ; } int [ ] prefixSum = new int [ N + 1 ] ; for ( int i = 1 ; i < ( N + 1 ) ; i ++ ) { prefixSum [ i ] = ( prefixSum [ i - 1 ] + arr [ i - 1 ] ) ; } int [ ] [ ] dp = new int [ N ] [ N ] ; for ( int L = K ; L < ( N + 1 ) ; L ++ ) { for ( int i = 0 ; i < ( N - L + 1 ) ; i ++ ) { int j = i + L - 1 ; if ( L > K ) { int temp = Integer . MAX_VALUE ; for ( int x = i ; x < j ; x += K - 1 ) { temp = Math . min ( temp , dp [ i ] [ x ] + dp [ x + 1 ] [ j ] ) ; } dp [ i ] [ j ] = temp ; } if ( ( L - 1 ) % ( K - 1 ) == 0 ) { dp [ i ] [ j ] += ( prefixSum [ j + 1 ] - prefixSum [ i ] ) ; } } } return dp [ 0 ] [ N - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 5 , 1 , 2 , 6 } ; int K = 3 ; int N = arr . length ; System . out . print ( minimumCostToMergeK ( arr , K , N ) ) ; } }

Index/key variables: N, i, j, x
Accumulator variables: L, i, x
Iterator variables: L, i, x
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int N = 8 ; static int check ( int [ ] [ ] memo , int i , int j , int [ ] A ) { if ( i == N - 1 ) return 1 ; if ( memo [ i ] [ j ] != - 1 ) return memo [ i ] [ j ] ; int flag = 0 , k ; for ( k = i + 1 ; k < N ; k ++ ) { if ( A [ k ] - A [ i ] > j + 1 ) break ; if ( A [ k ] - A [ i ] >= j - 1 && A [ k ] - A [ i ] <= j + 1 ) flag = check ( memo , k , A [ k ] - A [ i ] , A ) ; if ( flag != 0 ) break ; } memo [ i ] [ j ] = flag ; return memo [ i ] [ j ] ; } static void checkEndReach ( int A [ ] , int K ) { int [ ] [ ] memo = new int [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { memo [ i ] [ j ] = - 1 ; } } int startIndex = 1 ; if ( check ( memo , startIndex , K , A ) != 0 ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { int [ ] A = { 0 , 1 , 3 , 5 , 6 , 8 , 12 , 17 } ; int K = 1 ; checkEndReach ( A , K ) ; } }

Index/key variables: N, i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int Max_Sum ( int [ ] arr , int K , int N ) { int [ ] dp = new int [ N + 1 ] ; Arrays . fill ( dp , 0 ) ; int [ ] prefix = new int [ N + 1 ] ; prefix [ 0 ] = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { prefix [ i ] = prefix [ i - 1 ] + arr [ i - 1 ] ; } dp [ 0 ] = 0 ; for ( int i = 1 ; i <= K - 1 ; i ++ ) { dp [ i ] = prefix [ i ] ; } for ( int i = K ; i <= N ; ++ i ) { for ( int j = i ; j >= ( i - K + 1 ) ; j -- ) { dp [ i ] = Math . max ( dp [ i ] , dp [ j - 1 ] + prefix [ i ] - prefix [ j ] ) ; } } return dp [ N ] ; } public static void main ( String [ ] args ) { int [ ] arr = { 4 , 12 , 22 , 18 , 34 , 12 , 25 } ; int N = arr . length ; int K = 5 ; System . out . println ( Max_Sum ( arr , K , N ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int binomialCoeff ( int n , int k ) { int [ ] [ ] C = new int [ n + 1 ] [ k + 1 ] ; int i , j ; for ( i = 0 ; i <= n ; i ++ ) { for ( j = 0 ; j <= Math . min ( i , k ) ; j ++ ) { if ( j == 0 j == i ) C [ i ] [ j ] = 1 ; else C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ] ; } } return C [ n ] [ k ] ; } static int waysToSplitN ( int k , int n , int P ) { int new_N = n - k * P ; return binomialCoeff ( new_N + k - 1 , new_N ) ; } public static void main ( String [ ] args ) { int K = 3 , N = 8 , P = 2 ; System . out . print ( waysToSplitN ( K , N , P ) ) ; } }

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int solve ( int [ ] a ) { int n = a . length ; int [ ] dp = new int [ n + 1 ] ; int [ ] val = new int [ n + 1 ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { int sum = a [ i ] ; int j = i ; while ( j + 1 < n && sum < val [ j + 1 ] ) { j ++ ; sum += a [ j ] ; } dp [ i ] = ( j - i ) + dp [ j + 1 ] ; val [ i ] = sum ; } return dp [ 0 ] ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 5 , 3 , 9 , 1 } ; System . out . print ( solve ( arr ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Queue ; import java . util . LinkedList ; class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = null ; right = null ; } } class BinaryTree { Node root ; int getfullCount ( ) { if ( root == null ) return 0 ; Queue < Node > queue = new LinkedList < Node > ( ) ; queue . add ( root ) ; int count = 0 ; while ( ! queue . isEmpty ( ) ) { Node temp = queue . poll ( ) ; if ( temp . left != null && temp . right != null ) count ++ ; if ( temp . left != null ) { queue . add ( temp . left ) ; } if ( temp . right != null ) { queue . add ( temp . right ) ; } } return count ; } public static void main ( String args [ ] ) { BinaryTree tree_level = new BinaryTree ( ) ; tree_level . root = new Node ( 2 ) ; tree_level . root . left = new Node ( 7 ) ; tree_level . root . right = new Node ( 5 ) ; tree_level . root . left . right = new Node ( 6 ) ; tree_level . root . left . right . left = new Node ( 1 ) ; tree_level . root . left . right . right = new Node ( 11 ) ; tree_level . root . right . right = new Node ( 9 ) ; tree_level . root . right . right . left = new Node ( 4 ) ; System . out . println ( tree_level . getfullCount ( ) ) ; } }

Accumulator variables: count
Class/struct names: BinaryTree, Node
Java program:
import java . io . * ; import java . util . ArrayList ; class GFG { static int distinctSimilarSubstrings ( String str ) { int n = str . length ( ) ; if ( n <= 1 ) return 0 ; long dp [ ] [ ] = new long [ n + 1 ] [ n + 1 ] ; ArrayList < String > list = new ArrayList < String > ( ) ; for ( int j = n - 1 ; j >= 0 ; j -- ) { for ( int i = j - 1 ; i >= 0 ; i -- ) { if ( str . charAt ( i ) == str . charAt ( j ) ) { dp [ i ] [ j ] = dp [ i + 1 ] [ j + 1 ] + 1 ; } else { dp [ i ] [ j ] = 0 ; } if ( dp [ i ] [ j ] >= j - i ) { list . add ( str . substring ( j - i , i ) ) ; } } } return list . size ( ) ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; System . out . println ( distinctSimilarSubstrings ( str ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int MAXN = 100 ; static int INF = ( int ) 1e7 ; static int [ ] [ ] dis = new int [ MAXN ] [ MAXN ] ; static int [ ] [ ] Next = new int [ MAXN ] [ MAXN ] ; static void initialise ( int V , int [ ] [ ] graph ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { dis [ i ] [ j ] = graph [ i ] [ j ] ; if ( graph [ i ] [ j ] == INF ) Next [ i ] [ j ] = - 1 ; else Next [ i ] [ j ] = j ; } } } static Vector < Integer > constructPath ( int u , int v ) { if ( Next [ u ] [ v ] == - 1 ) return null ; Vector < Integer > path = new Vector < Integer > ( ) ; path . add ( u ) ; while ( u != v ) { u = Next [ u ] [ v ] ; path . add ( u ) ; } return path ; } static void floydWarshall ( int V ) { for ( int k = 0 ; k < V ; k ++ ) { for ( int i = 0 ; i < V ; i ++ ) { for ( int j = 0 ; j < V ; j ++ ) { if ( dis [ i ] [ k ] == INF dis [ k ] [ j ] == INF ) continue ; if ( dis [ i ] [ j ] > dis [ i ] [ k ] + dis [ k ] [ j ] ) { dis [ i ] [ j ] = dis [ i ] [ k ] + dis [ k ] [ j ] ; Next [ i ] [ j ] = Next [ i ] [ k ] ; } } } } } static void printPath ( Vector < Integer > path ) { int n = path . size ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) System . out . print ( path . get ( i ) + " ▁ - > ▁ " ) ; System . out . print ( path . get ( n - 1 ) + "NEW_LINE"); } public static void main ( String [ ] args ) { int V = 4 ; int [ ] [ ] graph = { { 0 , 3 , INF , 7 } , { 8 , 0 , 2 , INF } , { 5 , INF , 0 , 1 } , { 2 , INF , INF , 0 } } ; initialise ( V , graph ) ; floydWarshall ( V ) ; Vector < Integer > path ; System . out . print ( " Shortest ▁ path ▁ from ▁ 1 ▁ to ▁ 3 : ▁ " ) ; path = constructPath ( 1 , 3 ) ; printPath ( path ) ; System . out . print ( " Shortest ▁ path ▁ from ▁ 0 ▁ to ▁ 2 : ▁ " ) ; path = constructPath ( 0 , 2 ) ; printPath ( path ) ; System . out . print ( " Shortest ▁ path ▁ from ▁ 3 ▁ to ▁ 2 : ▁ " ) ; path = constructPath ( 3 , 2 ) ; printPath ( path ) ; } }

Index/key variables: MAXN, i, j, k, u, v
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { @ SuppressWarnings ( " unchecked " ) static Vector < Integer > [ ] vp = new Vector [ 2009 ] ; static void finding_factors ( int n ) { int i , a ; for ( i = 1 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { if ( i * i == n ) { vp [ n ] . add ( i ) ; } else { vp [ n ] . add ( i ) ; vp [ n ] . add ( n / i ) ; } } } } static int countSeq ( int N , int K ) { int i , j , k ; int dp [ ] [ ] = new int [ 109 ] [ 109 ] ; for ( i = 1 ; i <= N ; i ++ ) { finding_factors ( i ) ; dp [ 0 ] [ i ] = 0 ; dp [ 1 ] [ i ] = 1 ; } for ( i = 2 ; i <= K ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { int sum = 0 ; for ( k = 0 ; k < vp [ j ] . size ( ) ; k ++ ) { sum = ( sum + dp [ i - 1 ] [ vp [ j ] . get ( k ) ] ) ; } dp [ i ] [ j ] = sum ; } } int ans = 0 ; for ( j = 1 ; j <= N ; j ++ ) { ans = ( ans + dp [ K ] [ j ] ) ; } return ans ; } public static void main ( String [ ] args ) { int N , K ; N = 3 ; K = 2 ; for ( int i = 0 ; i < vp . length ; i ++ ) vp [ i ] = new Vector < Integer > ( ) ; System . out . print ( countSeq ( N , K ) + "NEW_LINE"); } }

Index/key variables: K, i, j, n
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MAX_value ( int [ ] [ ] arr ) { int row = arr . length ; int col = arr [ 0 ] . length ; int [ ] [ ] dp = new int [ row ] [ col ] ; int i = 0 , j = 0 ; int c = arr [ 0 ] [ 0 ] , p = 0 ; int d = row ; for ( i = 0 ; i < d ; i ++ ) { for ( j = 0 ; j < d ; j ++ ) { if ( c < arr [ i ] [ j ] ) { c = arr [ i ] [ j ] ; } if ( i == 0 j == 0 ) { dp [ i ] [ j ] = 1 ; } else { if ( arr [ i - 1 ] [ j - 1 ] == arr [ i ] [ j ] && arr [ i - 1 ] [ j ] == arr [ i ] [ j ] && arr [ i ] [ j - 1 ] == arr [ i ] [ j ] ) { dp [ i ] [ j ] = Math . min ( dp [ i - 1 ] [ j - 1 ] , Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ) + 1 ; } else { dp [ i ] [ j ] = 1 ; } } } } for ( i = 0 ; i < d ; i ++ ) { for ( j = 0 ; j < d ; j ++ ) { if ( arr [ i ] [ j ] == c ) { if ( p < dp [ i ] [ j ] ) { p = dp [ i ] [ j ] ; } } } } return p * p ; } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 9 , 9 , 3 , 3 , 4 , 4 } , { 9 , 9 , 7 , 7 , 7 , 4 } , { 1 , 2 , 7 , 7 , 7 , 4 } , { 4 , 4 , 7 , 7 , 7 , 4 } , { 5 , 5 , 1 , 1 , 2 , 7 } , { 2 , 7 , 1 , 1 , 4 , 4 } } ; System . out . print ( MAX_value ( arr ) + "NEW_LINE"); } }

Index/key variables: col, i, j, row
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int smallestNum ( int n ) { int res = 1 ; for ( int i = 2 ; ; i *= 2 ) { int length = ( int ) ( Math . log10 ( i ) ) + 1 ; if ( length == n ) return ( int ) ( Math . log ( i ) / Math . log ( 2 ) ) ; } } public static void main ( String [ ] args ) { int n = 4 ; System . out . print ( smallestNum ( n ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . awt . Point ; public class Main { static int N = 100005 ; static int [ ] level = new int [ N ] ; static int LG = 20 ; static int [ ] [ ] dp = new int [ LG ] [ N ] ; static int [ ] [ ] mx = new int [ LG ] [ N ] ; static Vector < Vector < Point > > v = new Vector < Vector < Point > > ( ) ; static int n = 0 ; static void dfs_lca ( int a , int par , int lev ) { dp [ 0 ] [ a ] = par ; level [ a ] = lev ; for ( int i = 0 ; i < v . get ( a ) . size ( ) ; i ++ ) { if ( v . get ( a ) . get ( i ) . x == par ) continue ; mx [ 0 ] [ v . get ( a ) . get ( i ) . x ] = v . get ( a ) . get ( i ) . y ; dfs_lca ( v . get ( a ) . get ( i ) . x , a , lev + 1 ) ; } } static void find_ancestor ( ) { for ( int i = 1 ; i < 16 ; i ++ ) { for ( int j = 1 ; j < n + 1 ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ dp [ i - 1 ] [ j ] ] ; mx [ i ] [ j ] = Math . max ( mx [ i - 1 ] [ j ] , mx [ i - 1 ] [ dp [ i - 1 ] [ j ] ] ) ; } } } static int getMax ( int a , int b ) { if ( level [ b ] < level [ a ] ) { int temp = a ; a = b ; b = temp ; } int ans = 0 ; int diff = level [ b ] - level [ a ] ; while ( diff > 0 ) { int log = ( int ) ( Math . log ( diff ) / Math . log ( 2 ) ) ; ans = Math . max ( ans , mx [ log ] [ b ] ) ; b = dp [ log ] [ b ] ; diff -= ( 1 << log ) ; } while ( a != b ) { int i = ( int ) ( Math . log ( level [ a ] ) / Math . log ( 2 ) ) ; while ( i > 0 && dp [ i ] [ a ] == dp [ i ] [ b ] ) { i -= 1 ; } ans = Math . max ( ans , mx [ i ] [ a ] ) ; ans = Math . max ( ans , mx [ i ] [ b ] ) ; a = dp [ i ] [ a ] ; b = dp [ i ] [ b ] ; } return ans ; } static void compute_lca ( ) { dfs_lca ( 1 , 0 , 0 ) ; find_ancestor ( ) ; } '' ' ▁ Driver ▁ Code ▁ ' '' public static void main ( String [ ] args ) { for ( int i = 0 ; i < LG ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { dp [ i ] [ j ] = 0 ; mx [ i ] [ j ] = 0 ; } } for ( int i = 0 ; i < N ; i ++ ) { v . add ( new Vector < Point > ( ) ) ; } v . get ( 1 ) . add ( new Point ( 2 , 2 ) ) ; v . get ( 2 ) . add ( new Point ( 1 , 2 ) ) ; v . get ( 1 ) . add ( new Point ( 3 , 5 ) ) ; v . get ( 3 ) . add ( new Point ( 1 , 5 ) ) ; v . get ( 3 ) . add ( new Point ( 4 , 3 ) ) ; v . get ( 4 ) . add ( new Point ( 3 , 4 ) ) ; v . get ( 3 ) . add ( new Point ( 5 , 1 ) ) ; v . get ( 5 ) . add ( new Point ( 3 , 1 ) ) ; compute_lca ( ) ; int [ ] [ ] queries = { { 3 , 5 } , { 2 , 3 } , { 2 , 4 } } ; int q = 3 ; for ( int i = 0 ; i < q ; i ++ ) { int max_edge = getMax ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ; System . out . println ( max_edge ) ; } } }

Index/key variables: LG, N, a, b, i, j, log
Accumulator variables: diff, i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
import java . util . * ; class GfG { static class Node { int data ; Node left , right ; } static int getfullCount ( Node root ) { if ( root == null ) return 0 ; int res = 0 ; if ( root . left != null && root . right != null ) res ++ ; res += ( getfullCount ( root . left ) + getfullCount ( root . right ) ) ; return res ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 2 ) ; root . left = newNode ( 7 ) ; root . right = newNode ( 5 ) ; root . left . right = newNode ( 6 ) ; root . left . right . left = newNode ( 1 ) ; root . left . right . right = newNode ( 11 ) ; root . right . right = newNode ( 9 ) ; root . right . right . left = newNode ( 4 ) ; System . out . println ( getfullCount ( root ) ) ; } }

Accumulator variables: res
Class/struct names: GfG, Node