dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int longestSubsequenceCommonSegment ( int k , string s1 , string s2 ) { int n = s1 . Length ; int m = s2 . Length ; int [ , ] lcs = new int [ n + 1 , m + 1 ] ; int [ , ] cnt = new int [ n + 1 , m + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { lcs [ i , j ] = Math . Max ( lcs [ i - 1 , j ] , lcs [ i , j - 1 ] ) ; if ( s1 [ i - 1 ] == s2 [ j - 1 ] ) cnt [ i , j ] = cnt [ i - 1 , j - 1 ] + 1 ; if ( cnt [ i , j ] >= k ) { for ( int a = k ; a <= cnt [ i , j ] ; a ++ ) lcs [ i , j ] = Math . Max ( lcs [ i , j ] , lcs [ i - a , j - a ] + a ) ; } } } return lcs [ n , m ] ; } public static void Main ( ) { int k = 4 ; string s1 = " aggasdfa " ; string s2 = " aggajasdfa " ; Console . WriteLine ( longestSubsequenceCommonSegment ( k , s1 , s2 ) ) ; } }

Accumulator variables: a, i, j
Iterator variables: a, i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections ; class GFG { static int row = 5 ; static int col = 5 ; static bool isPath ( int [ , ] arr ) { int [ , ] dir = { { 0 , 1 } , { 0 , - 1 } , { 1 , 0 } , { - 1 , 0 } } ; Queue q = new Queue ( ) ; q . Enqueue ( new Tuple < int , int > ( 0 , 0 ) ) ; while ( q . Count > 0 ) { Tuple < int , int > p = ( Tuple < int , int > ) ( q . Peek ( ) ) ; q . Dequeue ( ) ; arr [ p . Item1 , p . Item2 ] = - 1 ; if ( p == new Tuple < int , int > ( row - 1 , col - 1 ) ) return true ; for ( int i = 0 ; i < 4 ; i ++ ) { int a = p . Item1 + dir [ i , 0 ] ; int b = p . Item2 + dir [ i , 1 ] ; if ( a >= 0 && b >= 0 && a < row && b < col && arr [ a , b ] != - 1 ) { q . Enqueue ( new Tuple < int , int > ( a , b ) ) ; } } } return false ; } static void Main ( ) { int [ , ] arr = { { 0 , 0 , 0 , - 1 , 0 } , { - 1 , 0 , 0 , - 1 , - 1 } , { 0 , 0 , 0 , - 1 , 0 } , { - 1 , 0 , - 1 , 0 , - 1 } , { 0 , 0 , - 1 , 0 , 0 } } ; if ( isPath ( arr ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int start , finish ; static void longSubarrWthSumDivByK ( int [ ] arr , int n , int k ) { Dictionary < int , int > um = new Dictionary < int , int > ( ) ; int [ ] mod_arr = new int [ n ] ; int curr_sum = 0 , max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { curr_sum += arr [ i ] ; mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ; } for ( int i = 0 ; i < n ; i ++ ) { if ( mod_arr [ i ] == 0 ) { max = i + 1 ; start = 0 ; finish = i ; } else if ( ! um . ContainsKey ( mod_arr [ i ] ) ) um . Add ( mod_arr [ i ] , i ) ; else if ( max < ( i - um [ mod_arr [ i ] ] ) ) { max = i - um [ mod_arr [ i ] ] ; start = um [ mod_arr [ i ] ] + 1 ; finish = i ; } } } static void findLargestSubmatrix ( int [ , ] mat , int n , int k ) { int finalLeft = 0 , finalRight = 0 , finalTop = 0 , finalBottom = 0 ; int left , right , i , maxArea = 0 ; int [ ] temp ; for ( left = 0 ; left < n ; left ++ ) { temp = new int [ n ] ; for ( right = left ; right < n ; right ++ ) { for ( i = 0 ; i < n ; ++ i ) temp [ i ] += mat [ i , right ] ; longSubarrWthSumDivByK ( temp , n , k ) ; if ( maxArea < ( ( right - left + 1 ) * ( finish - start + 1 ) ) ) { finalLeft = left ; finalRight = right ; finalTop = start ; finalBottom = finish ; maxArea = ( right - left + 1 ) * ( finish - start + 1 ) ; } } } Console . Write ( " ( Top , ▁ Left ) : ▁ ( " + finalTop + " , ▁ " + finalLeft + " ) STRNEWLINE " ) ; Console . Write ( " ( Bottom , ▁ Right ) : ▁ ( " + finalBottom + " , ▁ " + finalRight + " ) STRNEWLINE " ) ; Console . Write ( " Area : ▁ " + maxArea ) ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 1 , 2 , - 1 , - 4 } , { - 8 , - 3 , 4 , 2 } , { 3 , 8 , 10 , 1 } , { - 4 , - 1 , 1 , 7 } } ; int n = 4 , k = 5 ; findLargestSubmatrix ( mat , n , k ) ; } }

Index/key variables: i, n
Accumulator variables: curr_sum, i, left, right
Iterator variables: i, left, right
Class/struct names: GFG
C# program:
using System ; class GFG { static int zigzag ( int n , int k ) { int [ , ] dp = new int [ n + 1 , k + 1 ] ; dp [ 0 , 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) dp [ i , 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= Math . Min ( i , k ) ; j ++ ) dp [ i , j ] = dp [ i , j - 1 ] + dp [ i - 1 , i - j ] ; } return dp [ n , k ] ; } public static void Main ( ) { int n = 4 , k = 3 ; Console . WriteLine ( zigzag ( n , k ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int binomialCoeff ( int n , int k ) { int [ , ] C = new int [ n + 1 , k + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int 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 lobb ( int n , int m ) { return ( ( 2 * m + 1 ) * binomialCoeff ( 2 * n , m + n ) ) / ( m + n + 1 ) ; } public static void Main ( ) { int n = 5 , m = 3 ; Console . WriteLine ( lobb ( n , m ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static int countarray ( int n , int k , int x ) { int [ ] dp = new int [ 109 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; for ( int i = 2 ; i < n ; i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ; return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ; } public static void Main ( ) { int n = 4 , k = 3 , x = 2 ; Console . WriteLine ( countarray ( n , k , x ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 100 ; static int MAX_CHAR = 26 ; static void precompute ( string s , int n , int [ , ] l , int [ , ] r ) { l [ s [ 0 ] - ' a ' , 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < MAX_CHAR ; j ++ ) l [ j , i ] += l [ j , i - 1 ] ; l [ s [ i ] - ' a ' , i ] ++ ; } r [ s [ n - 1 ] - ' a ' , n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < MAX_CHAR ; j ++ ) r [ j , i ] += r [ j , i + 1 ] ; r [ s [ i ] - ' a ' , i ] ++ ; } } static int countPalindromes ( int k , int n , int [ , ] l , int [ , ] r ) { int ans = 0 ; if ( k == 1 ) { for ( int i = 0 ; i < MAX_CHAR ; i ++ ) ans += l [ i , n - 1 ] ; return ans ; } if ( k == 2 ) { for ( int i = 0 ; i < MAX_CHAR ; i ++ ) ans += ( ( l [ i , n - 1 ] * ( l [ i , n - 1 ] - 1 ) ) / 2 ) ; return ans ; } for ( int i = 1 ; i < n - 1 ; i ++ ) for ( int j = 0 ; j < MAX_CHAR ; j ++ ) ans += l [ j , i - 1 ] * r [ j , i + 1 ] ; return ans ; } public static void Main ( ) { string s = " aabab " ; int k = 2 ; int n = s . Length ; int [ , ] l = new int [ MAX_CHAR , MAX ] ; int [ , ] r = new int [ MAX_CHAR , MAX ] ; precompute ( s , n , l , r ) ; Console . Write ( countPalindromes ( k , n , l , r ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 30 ; static int solve ( char [ ] X , char [ ] Y , int l , int r , int k , int [ , , ] dp ) { if ( k == 0 ) { return 0 ; } if ( l < 0 r < 0 ) { return ( int ) 1e9 ; } if ( dp [ l , r , k ] != - 1 ) { return dp [ l , r , k ] ; } int cost = ( X [ l ] - ' a ' ) ^ ( Y [ r ] - ' a ' ) ; return dp [ l , r , k ] = Math . Min ( Math . Min ( cost + solve ( X , Y , l - 1 , r - 1 , k - 1 , dp ) , solve ( X , Y , l - 1 , r , k , dp ) ) , solve ( X , Y , l , r - 1 , k , dp ) ) ; } public static void Main ( String [ ] args ) { char [ ] X = " abble " . ToCharArray ( ) ; char [ ] Y = " pie " . ToCharArray ( ) ; int n = X . Length ; int m = Y . Length ; int k = 2 ; int [ , , ] dp = new int [ N , N , N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int l = 0 ; l < N ; l ++ ) { dp [ i , j , l ] = - 1 ; } } } int ans = solve ( X , Y , n - 1 , m - 1 , k , dp ) ; Console . WriteLine ( ans == 1e9 ? - 1 : ans ) ; } }

Index/key variables: l, r
Accumulator variables: i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class MaxSumPath { static int maxSum ( int [ , ] mat , int n ) { if ( n == 1 ) return mat [ 0 , 0 ] ; int [ , ] dp = new int [ n , n ] ; int maxSum = int . MinValue , max ; for ( int j = 0 ; j < n ; j ++ ) dp [ n - 1 , j ] = mat [ n - 1 , j ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < n ; j ++ ) { max = int . MinValue ; if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 , j - 1 ] ) ) max = dp [ i + 1 , j - 1 ] ; if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 , j + 1 ] ) ) max = dp [ i + 1 , j + 1 ] ; dp [ i , j ] = mat [ i , j ] + max ; } } for ( int j = 0 ; j < n ; j ++ ) if ( maxSum < dp [ 0 , j ] ) maxSum = dp [ 0 , j ] ; return maxSum ; } public static void Main ( ) { int [ , ] mat = { { 5 , 6 , 1 , 7 } , { - 2 , 10 , 8 , - 1 } , { 3 , - 7 , - 9 , 11 } , { 12 , - 4 , 2 , 6 } } ; int n = 4 ; Console . WriteLine ( " Maximum ▁ Sum ▁ = ▁ " + maxSum ( mat , n ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: MaxSumPath
C# program:
using System ; using System . Collections . Generic ; class GFG { static String longestRepeatedSubSeq ( String str ) { int n = str . Length , i , j ; int [ , ] dp = new int [ n + 1 , n + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) for ( j = 0 ; j <= n ; j ++ ) dp [ i , j ] = 0 ; for ( i = 1 ; i <= n ; i ++ ) for ( j = 1 ; j <= n ; j ++ ) if ( str [ i - 1 ] == str [ j - 1 ] && i != j ) dp [ i , j ] = 1 + dp [ i - 1 , j - 1 ] ; else dp [ i , j ] = Math . Max ( dp [ i , j - 1 ] , dp [ i - 1 , j ] ) ; String res = " " ; i = n ; j = n ; while ( i > 0 && j > 0 ) { if ( dp [ i , j ] == dp [ i - 1 , j - 1 ] + 1 ) { res = res + str [ i - 1 ] ; i -- ; j -- ; } else if ( dp [ i , j ] == dp [ i - 1 , j ] ) i -- ; else j -- ; } String reverse = " " ; for ( int k = res . Length - 1 ; k >= 0 ; k -- ) { reverse = reverse + res [ k ] ; } return reverse ; } public static void Main ( String [ ] args ) { String str = " AABEBCDD " ; Console . WriteLine ( longestRepeatedSubSeq ( str ) ) ; } }

Index/key variables: k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void dfs ( int node , int parent , List < int > [ ] tree , int [ ] colour , int [ ] answer ) { answer [ node ] = colour [ node ] ; foreach ( int u in tree [ node ] ) { if ( u == parent ) continue ; dfs ( u , node , tree , colour , answer ) ; answer [ node ] += Math . Max ( answer [ u ] , 0 ) ; } } static int maxDiff ( List < int > [ ] tree , int [ ] colour , int N ) { int [ ] answer = new int [ N + 1 ] ; dfs ( 1 , 0 , tree , colour , answer ) ; int high = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { high = Math . Max ( high , answer [ i ] ) ; answer [ i ] = 0 ; } for ( int i = 1 ; i <= N ; i ++ ) { if ( colour [ i ] == - 1 ) colour [ i ] = 1 ; else colour [ i ] = - 1 ; } dfs ( 1 , 0 , tree , colour , answer ) ; for ( int i = 1 ; i < N ; i ++ ) high = Math . Max ( high , answer [ i ] ) ; return high ; } public static void Main ( String [ ] args ) { int N = 5 ; List < int > [ ] tree = new List < int > [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) tree [ i ] = new List < int > ( ) ; tree [ 1 ] . Add ( 2 ) ; tree [ 2 ] . Add ( 1 ) ; tree [ 1 ] . Add ( 3 ) ; tree [ 3 ] . Add ( 1 ) ; tree [ 2 ] . Add ( 4 ) ; tree [ 4 ] . Add ( 2 ) ; tree [ 3 ] . Add ( 5 ) ; tree [ 5 ] . Add ( 3 ) ; int [ ] colour = { 0 , 1 , 1 , - 1 , - 1 , 1 } ; Console . WriteLine ( maxDiff ( tree , colour , N ) ) ; } }

Index/key variables: i, node, u
Accumulator variables: i
Iterator variables: i, u
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 50 ; static int solve ( int [ , ] dp , int [ ] a , int low , int high , int turn ) { if ( low == high ) return a [ low ] * turn ; if ( dp [ low , high ] != 0 ) return dp [ low , high ] ; dp [ low , high ] = Math . Max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ; return dp [ low , high ] ; } static void Main ( ) { int [ ] arr = new int [ ] { 1 , 3 , 1 , 5 , 2 } ; int n = arr . Length ; int [ , ] dp = new int [ MAX , MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) for ( int j = 0 ; j < MAX ; j ++ ) dp [ i , j ] = 0 ; Console . Write ( solve ( dp , arr , 0 , n - 1 , 1 ) ) ; } }

Index/key variables: high, low
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxSumBitonicSubArr ( int [ ] arr , int n ) { int [ ] msis = new int [ n ] ; int [ ] msds = new int [ n ] ; int max_sum = int . MinValue ; msis [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ; else msis [ i ] = arr [ i ] ; msds [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ; else msds [ i ] = arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ; return max_sum ; } public static void Main ( ) { int [ ] arr = { 5 , 3 , 9 , 2 , 7 , 6 , 4 } ; int n = arr . Length ; Console . Write ( " Maximum ▁ Sum ▁ = ▁ " + maxSumBitonicSubArr ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; public class GFG_1 { static void printSuperSeq ( string a , string b ) { int m = a . Length , n = b . Length ; int [ , ] dp = new int [ m + 1 , n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 ) dp [ i , j ] = j ; else if ( j == 0 ) dp [ i , j ] = i ; else if ( a [ i - 1 ] == b [ j - 1 ] ) dp [ i , j ] = 1 + dp [ i - 1 , j - 1 ] ; else dp [ i , j ] = 1 + Math . Min ( dp [ i - 1 , j ] , dp [ i , j - 1 ] ) ; } } string res = " " ; int k = m , l = n ; while ( k > 0 && l > 0 ) { if ( a [ k - 1 ] == b [ l - 1 ] ) { res = a [ k - 1 ] + res ; k -- ; l -- ; } else if ( dp [ k - 1 , l ] < dp [ k , l - 1 ] ) { res = a [ k - 1 ] + res ; k -- ; } else { res = b [ l - 1 ] + res ; l -- ; } } while ( k > 0 ) { res = a [ k - 1 ] + res ; k -- ; } while ( l > 0 ) { res = b [ l - 1 ] + res ; l -- ; } Console . WriteLine ( res ) ; } public static void Main ( ) { string a = " algorithm " ; string b = " rhythm " ; printSuperSeq ( a , b ) ; } }

Accumulator variables: i, j, k, l
Iterator variables: i, j
Class/struct names: GFG_1
C# program:
using System ; public class GFG { static int maxSubsequenceSubString ( String X , String Y , int n , int m ) { if ( n == 0 m == 0 ) return 0 ; if ( X [ n - 1 ] == Y [ m - 1 ] ) { return 1 + maxSubsequenceSubString ( X , Y , n - 1 , m - 1 ) ; } else { return maxSubsequenceSubString ( X , Y , n - 1 , m ) ; } } public static void Main ( String [ ] args ) { String X = " abcd " ; String Y = " bacdbdcd " ; int n = X . Length , m = Y . Length ; int maximum_length = 0 ; for ( int i = 0 ; i <= m ; i ++ ) { int temp_ans = maxSubsequenceSubString ( X , Y , n , i ) ; if ( temp_ans > maximum_length ) maximum_length = temp_ans ; } Console . Write ( " Length ▁ for ▁ maximum ▁ possible ▁ Subsequence ▁ of ▁ String ▁ X ▁ which ▁ is ▁ SubString ▁ of ▁ Y - > " + maximum_length ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int minTimeForWritingChars ( int N , int insert , int remove , int copy ) { if ( N == 0 ) return 0 ; if ( N == 1 ) return insert ; int [ ] dp = new int [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) dp [ i ] = 0 ; dp [ 1 ] = insert ; for ( int i = 2 ; i <= N ; i ++ ) { if ( i % 2 == 0 ) dp [ i ] = Math . Min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ; else dp [ i ] = Math . Min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ; } return dp [ N ] ; } static void Main ( ) { int N = 9 ; int insert = 1 , remove = 2 , copy = 1 ; Console . Write ( minTimeForWritingChars ( N , insert , remove , copy ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int countWays ( int n , int m ) { int [ ] count = new int [ n + 1 ] ; count [ 0 ] = 0 ; int i ; for ( i = 1 ; i <= n ; i ++ ) { if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ; else if ( i < m == 1 ) count [ i ] = 1 ; else count [ i ] = 2 ; } return count [ n ] ; } public static void Main ( ) { int n = 7 ; int m = 4 ; Console . Write ( " Number ▁ of ▁ ways ▁ = ▁ " + countWays ( n , m ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int LAS ( int [ ] arr , int n ) { int inc = 1 ; int dec = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) { inc = dec + 1 ; } else if ( arr [ i ] < arr [ i - 1 ] ) { dec = inc + 1 ; } } return Math . Max ( inc , dec ) ; } static void Main ( ) { int [ ] arr = { 10 , 22 , 9 , 33 , 49 , 50 , 31 , 60 } ; int n = arr . Length ; Console . WriteLine ( LAS ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int min ( int x , int y ) { return ( x < y ) ? x : y ; } static int utility_fun_for_del ( string str , int i , int j ) { if ( i >= j ) return 0 ; if ( str [ i ] == str [ j ] ) { return utility_fun_for_del ( str , i + 1 , j - 1 ) ; } return 1 + Math . Min ( utility_fun_for_del ( str , i + 1 , j ) , utility_fun_for_del ( str , i , j - 1 ) ) ; } static int min_ele_del ( string str ) { return utility_fun_for_del ( str , 0 , str . Length - 1 ) ; } static void Main ( ) { string str = " abefbac " ; Console . WriteLine ( " Minimum ▁ element ▁ of ▁ " + " deletions ▁ = ▁ " + min_ele_del ( str ) ) ; } }

Index/key variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ , ] dp = new int [ 2000 , 2000 ] ; static int transformation ( string s1 , string s2 , int i , int j ) { if ( i >= ( s1 . Length ) || j >= ( s2 . Length ) ) { return 0 ; } if ( s1 [ i ] == s2 [ j ] ) { dp [ i , j ] = 1 + transformation ( s1 , s2 , i + 1 , j + 1 ) ; } if ( dp [ i , j ] != - 1 ) { return dp [ i , j ] ; } else { dp [ i , j ] = Math . Max ( transformation ( s1 , s2 , i , j + i ) , transformation ( s1 , s2 , i + 1 , j ) ) ; } return dp [ s1 . Length - 1 , s2 . Length - 1 ] ; } static public void Main ( ) { string s1 = " geeksforgeeks " ; string s2 = " geeks " ; for ( int m = 0 ; m < 2000 ; m ++ ) { for ( int n = 0 ; n < 2000 ; n ++ ) { dp [ m , n ] = - 1 ; } } Console . WriteLine ( " MINIMUM ▁ NUMBER ▁ OF ▁ DELETIONS : ▁ " + ( s1 . Length - transformation ( s1 , s2 , 0 , 0 ) ) ) ; Console . WriteLine ( " MINIMUM ▁ NUMBER ▁ OF ▁ INSERTIONS : ▁ " + ( s2 . Length - transformation ( s1 , s2 , 0 , 0 ) ) ) ; Console . WriteLine ( " LCS ▁ LENGTH : ▁ " + transformation ( s1 , s2 , 0 , 0 ) ) ; } }

Index/key variables: i, j
Accumulator variables: m, n
Iterator variables: m, n
Class/struct names: GFG
C# program:
using System ; class GFG { static int largestZigZagSumRec ( int [ , ] mat , int i , int j , int n ) { if ( i == n - 1 ) return mat [ i , j ] ; int zzs = 0 ; for ( int k = 0 ; k < n ; k ++ ) if ( k != j ) zzs = Math . Max ( zzs , largestZigZagSumRec ( mat , i + 1 , k , n ) ) ; return zzs + mat [ i , j ] ; } static int largestZigZag ( int [ , ] mat , int n ) { int res = 0 ; for ( int j = 0 ; j < n ; j ++ ) res = Math . Max ( res , largestZigZagSumRec ( mat , 0 , j , n ) ) ; return res ; } public static void Main ( ) { int n = 3 ; int [ , ] mat = { { 4 , 2 , 1 } , { 3 , 9 , 6 } , { 11 , 3 , 15 } } ; Console . WriteLine ( " Largest ▁ zigzag ▁ sum : ▁ " + largestZigZag ( mat , n ) ) ; } }

Accumulator variables: j, k
Iterator variables: j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int M = 26 ; static int waysToIncreaseLCSBy1 ( String str1 , String str2 ) { int m = str1 . Length , n = str2 . Length ; List < int > [ ] position = new List < int > [ M ] ; for ( int i = 0 ; i < M ; i ++ ) position [ i ] = new List < int > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) position [ str2 [ i - 1 ] - ' a ' ] . Add ( i ) ; int [ , ] lcsl = new int [ m + 2 , n + 2 ] ; int [ , ] lcsr = new int [ m + 2 , n + 2 ] ; for ( int i = 0 ; i <= m + 1 ; i ++ ) for ( int j = 0 ; j <= n + 1 ; j ++ ) lcsl [ i , j ] = lcsr [ i , j ] = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsl [ i , j ] = 1 + lcsl [ i - 1 , j - 1 ] ; else lcsl [ i , j ] = Math . Max ( lcsl [ i - 1 , j ] , lcsl [ i , j - 1 ] ) ; } } for ( int i = m ; i >= 1 ; i -- ) { for ( int j = n ; j >= 1 ; j -- ) { if ( str1 [ i - 1 ] == str2 [ j - 1 ] ) lcsr [ i , j ] = 1 + lcsr [ i + 1 , j + 1 ] ; else lcsr [ i , j ] = Math . Max ( lcsr [ i + 1 , j ] , lcsr [ i , j + 1 ] ) ; } } int ways = 0 ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int d = 0 ; d < 26 ; d ++ ) { for ( int j = 0 ; j < position [ d ] . Count ; j ++ ) { int p = position [ d ] [ j ] ; if ( lcsl [ i , p - 1 ] + lcsr [ i + 1 , p + 1 ] == lcsl [ m , n ] ) ways ++ ; } } } return ways ; } public static void Main ( String [ ] args ) { String str1 = " abcabc " ; String str2 = " abcd " ; Console . WriteLine ( waysToIncreaseLCSBy1 ( str1 , str2 ) ) ; } }

Index/key variables: M, d, i, j
Accumulator variables: d, i, j, ways
Iterator variables: d, i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countStr ( int n , int bCount , int cCount ) { if ( bCount < 0 cCount < 0 ) return 0 ; if ( n == 0 ) return 1 ; if ( bCount == 0 && cCount == 0 ) return 1 ; int res = countStr ( n - 1 , bCount , cCount ) ; res += countStr ( n - 1 , bCount - 1 , cCount ) ; res += countStr ( n - 1 , bCount , cCount - 1 ) ; return res ; } static public void Main ( ) { int n = 3 ; Console . WriteLine ( countStr ( n , 1 , 2 ) ) ; } }

Accumulator variables: res
Class/struct names: GFG
C# program:
using System ; class GFG { static int N = 4 ; static int MaximumPath ( int [ , ] Mat ) { int result = 0 ; int [ , ] dp = new int [ N , N + 2 ] ; for ( int i = 0 ; i < N ; i ++ ) dp [ 0 , i + 1 ] = Mat [ 0 , i ] ; for ( int i = 1 ; i < N ; i ++ ) for ( int j = 1 ; j <= N ; j ++ ) dp [ i , j ] = Math . Max ( dp [ i - 1 , j - 1 ] , Math . Max ( dp [ i - 1 , j ] , dp [ i - 1 , j + 1 ] ) ) + Mat [ i , j - 1 ] ; for ( int i = 0 ; i <= N ; i ++ ) result = Math . Max ( result , dp [ N - 1 , i ] ) ; return result ; } public static void Main ( ) { int [ , ] Mat = { { 4 , 2 , 3 , 4 } , { 2 , 9 , 1 , 10 } , { 15 , 1 , 3 , 0 } , { 16 , 92 , 41 , 44 } } ; Console . WriteLine ( MaximumPath ( Mat ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 100001 ; static double [ ] dp = new double [ MAX ] ; static double probability ( int k , int n ) { double ans = 0.0 ; for ( int i = k ; i <= n ; ++ i ) { double res = dp [ n ] - dp [ i ] - dp [ n - i ] - n ; ans += Math . Pow ( 2.0 , res ) ; } return ans ; } static void precompute ( ) { for ( int i = 2 ; i < MAX ; ++ i ) dp [ i ] = ( Math . Log ( i ) / Math . Log ( 2 ) ) + dp [ i - 1 ] ; } public static void Main ( ) { precompute ( ) ; Console . WriteLine ( probability ( 2 , 3 ) ) ; Console . WriteLine ( probability ( 3 , 6 ) ) ; Console . WriteLine ( Math . Round ( probability ( 500 , 1000 ) , 6 ) ) ; } }

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