dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static int knapSack ( int W , int [ ] wt , int [ ] val , int n ) { int i , w ; int [ , ] K = new int [ n + 1 , W + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) { for ( w = 0 ; w <= W ; w ++ ) { if ( i == 0 w == 0 ) K [ i , w ] = 0 ; else if ( wt [ i - 1 ] <= w ) K [ i , w ] = Math . Max ( val [ i - 1 ] + K [ i - 1 , w - wt [ i - 1 ] ] , K [ i - 1 , w ] ) ; else K [ i , w ] = K [ i - 1 , w ] ; } } return K [ n , W ] ; } static void Main ( ) { int [ ] val = new int [ ] { 60 , 100 , 120 } ; int [ ] wt = new int [ ] { 10 , 20 , 30 } ; int W = 50 ; int n = val . Length ; Console . WriteLine ( knapSack ( W , wt , val , n ) ) ; } }

Accumulator variables: i, w
Iterator variables: i, w
Class/struct names: GFG
C# program:
using System ; class GFG { static int max ( int x , int y ) { return ( x > y ) ? x : y ; } static int lps ( string seq ) { int n = seq . Length ; int i , j , cl ; int [ , ] L = new int [ n , n ] ; for ( i = 0 ; i < n ; i ++ ) L [ i , i ] = 1 ; for ( cl = 2 ; cl <= n ; cl ++ ) { for ( i = 0 ; i < n - cl + 1 ; i ++ ) { j = i + cl - 1 ; if ( seq [ i ] == seq [ j ] && cl == 2 ) L [ i , j ] = 2 ; else if ( seq [ i ] == seq [ j ] ) L [ i , j ] = L [ i + 1 , j - 1 ] + 2 ; else L [ i , j ] = max ( L [ i , j - 1 ] , L [ i + 1 , j ] ) ; } } return L [ 0 , n - 1 ] ; } public static void Main ( ) { string seq = " GEEKS ▁ FOR ▁ GEEKS " ; int n = seq . Length ; Console . Write ( " The ▁ length ▁ of ▁ the ▁ " + " lps ▁ is ▁ " + lps ( seq ) ) ; } }

Index/key variables: i, j
Accumulator variables: cl, i
Iterator variables: cl, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxDivide ( int a , int b ) { while ( a % b == 0 ) a = a / b ; return a ; } static int isUgly ( int no ) { no = maxDivide ( no , 2 ) ; no = maxDivide ( no , 3 ) ; no = maxDivide ( no , 5 ) ; return ( no == 1 ) ? 1 : 0 ; } static int getNthUglyNo ( int n ) { int i = 1 ; int count = 1 ; while ( n > count ) { i ++ ; if ( isUgly ( i ) == 1 ) count ++ ; } return i ; } public static void Main ( ) { int no = getNthUglyNo ( 150 ) ; Console . WriteLine ( "150th ▁ ugly " + " ▁ no . ▁ is ▁ " + no ) ; } }

Accumulator variables: count, i
Class/struct names: GFG
C# program:
using System ; class GFG { static void printSubStr ( String str , int low , int high ) { for ( int i = low ; i <= high ; ++ i ) Console . Write ( str [ i ] ) ; } static int longestPalSubstr ( String str ) { int n = str . Length ; int maxLength = 1 , start = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) { for ( int j = i ; j < str . Length ; j ++ ) { int flag = 1 ; for ( int k = 0 ; k < ( j - i + 1 ) / 2 ; k ++ ) if ( str [ i + k ] != str [ j - k ] ) flag = 0 ; if ( flag != 0 && ( j - i + 1 ) > maxLength ) { start = i ; maxLength = j - i + 1 ; } } } Console . Write ( " longest ▁ palindrome ▁ subString ▁ is : ▁ " ) ; printSubStr ( str , start , start + maxLength - 1 ) ; return maxLength ; } public static void Main ( String [ ] args ) { String str = " forgeeksskeegfor " ; Console . Write ( " Length is : " + longestPalSubstr ( str ) ) ; } }

Index/key variables: i
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static void printSubStr ( string str , int low , int high ) { Console . WriteLine ( str . Substring ( low , high - low + 1 ) ) ; } static int longestPalSubstr ( string str ) { int n = str . Length ; bool [ , ] table = new bool [ n , n ] ; int maxLength = 1 ; for ( int i = 0 ; i < n ; ++ i ) table [ i , i ] = true ; int start = 0 ; for ( int i = 0 ; i < n - 1 ; ++ i ) { if ( str [ i ] == str [ i + 1 ] ) { table [ i , i + 1 ] = true ; start = i ; maxLength = 2 ; } } for ( int k = 3 ; k <= n ; ++ k ) { for ( int i = 0 ; i < n - k + 1 ; ++ i ) { int j = i + k - 1 ; if ( table [ i + 1 , j - 1 ] && str [ i ] == str [ j ] ) { table [ i , j ] = true ; if ( k > maxLength ) { start = i ; maxLength = k ; } } } } Console . Write ( " Longest ▁ palindrome ▁ substring ▁ is : ▁ " ) ; printSubStr ( str , start , start + maxLength - 1 ) ; return maxLength ; } public static void Main ( string [ ] args ) { string str = " forgeeksskeegfor " ; Console . WriteLine ( " Length ▁ is : ▁ " + longestPalSubstr ( str ) ) ; } }

Index/key variables: i, j
Iterator variables: i, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int sum ( int [ ] freq , int i , int j ) { int s = 0 ; for ( int k = i ; k <= j ; k ++ ) s += freq [ k ] ; return s ; } static int optCost ( int [ ] freq , int i , int j ) { if ( j < i ) return 0 ; if ( j == i ) return freq [ i ] ; int fsum = sum ( freq , i , j ) ; int min = int . MaxValue ; for ( int r = i ; r <= j ; ++ r ) { int cost = optCost ( freq , i , r - 1 ) + optCost ( freq , r + 1 , j ) ; if ( cost < min ) min = cost ; } return min + fsum ; } static int optimalSearchTree ( int [ ] keys , int [ ] freq , int n ) { return optCost ( freq , 0 , n - 1 ) ; } public static void Main ( ) { int [ ] keys = { 10 , 12 , 20 } ; int [ ] freq = { 34 , 8 , 50 } ; int n = keys . Length ; Console . Write ( " Cost ▁ of ▁ Optimal ▁ BST ▁ is ▁ " + optimalSearchTree ( keys , freq , n ) ) ; } }

Index/key variables: i, k
Accumulator variables: k, s
Iterator variables: k, r
Class/struct names: GFG
C# program:
using System ; class GFG { static int sum ( int [ ] freq , int i , int j ) { int s = 0 ; for ( int k = i ; k <= j ; k ++ ) { if ( k >= freq . Length ) continue ; s += freq [ k ] ; } return s ; } static int optimalSearchTree ( int [ ] keys , int [ ] freq , int n ) { int [ , ] cost = new int [ n + 1 , n + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) cost [ i , i ] = freq [ i ] ; for ( int L = 2 ; L <= n ; L ++ ) { for ( int i = 0 ; i <= n - L + 1 ; i ++ ) { int j = i + L - 1 ; cost [ i , j ] = int . MaxValue ; for ( int r = i ; r <= j ; r ++ ) { int c = ( ( r > i ) ? cost [ i , r - 1 ] : 0 ) + ( ( r < j ) ? cost [ r + 1 , j ] : 0 ) + sum ( freq , i , j ) ; if ( c < cost [ i , j ] ) cost [ i , j ] = c ; } } } return cost [ 0 , n - 1 ] ; } public static void Main ( ) { int [ ] keys = { 10 , 12 , 20 } ; int [ ] freq = { 34 , 8 , 50 } ; int n = keys . Length ; Console . Write ( " Cost ▁ of ▁ Optimal ▁ BST ▁ is ▁ " + optimalSearchTree ( keys , freq , n ) ) ; } }

Index/key variables: i, k
Accumulator variables: L, i, k, r, s
Iterator variables: L, i, k, r
Class/struct names: GFG
C# program:
using System ; class LisTree { public class node { public int data , liss ; public node left , right ; public node ( int data ) { this . data = data ; this . liss = 0 ; } } static int liss ( node root ) { if ( root == null ) return 0 ; if ( root . liss != 0 ) return root . liss ; if ( root . left == null && root . right == null ) return root . liss = 1 ; int liss_excl = liss ( root . left ) + liss ( root . right ) ; int liss_incl = 1 ; if ( root . left != null ) { liss_incl += ( liss ( root . left . left ) + liss ( root . left . right ) ) ; } if ( root . right != null ) { liss_incl += ( liss ( root . right . left ) + liss ( root . right . right ) ) ; } return root . liss = Math . Max ( liss_excl , liss_incl ) ; } public static void Main ( String [ ] args ) { node root = new node ( 20 ) ; root . left = new node ( 8 ) ; root . left . left = new node ( 4 ) ; root . left . right = new node ( 12 ) ; root . left . right . left = new node ( 10 ) ; root . left . right . right = new node ( 14 ) ; root . right = new node ( 22 ) ; root . right . right = new node ( 25 ) ; Console . WriteLine ( " Size ▁ of ▁ the ▁ Largest ▁ Independent ▁ Set ▁ is ▁ " + liss ( root ) ) ; } }

Accumulator variables: liss_incl
Class/struct names: LisTree, node
C# program:
using System ; class GFG { static int countParenth ( char [ ] symb , char [ ] oper , int n ) { int [ , ] F = new int [ n , n ] ; int [ , ] T = new int [ n , n ] ; for ( int i = 0 ; i < n ; i ++ ) { F [ i , i ] = ( symb [ i ] == ' F ' ) ? 1 : 0 ; T [ i , i ] = ( symb [ i ] == ' T ' ) ? 1 : 0 ; } for ( int gap = 1 ; gap < n ; ++ gap ) { for ( int i = 0 , j = gap ; j < n ; ++ i , ++ j ) { T [ i , j ] = F [ i , j ] = 0 ; for ( int g = 0 ; g < gap ; g ++ ) { int k = i + g ; int tik = T [ i , k ] + F [ i , k ] ; int tkj = T [ k + 1 , j ] + F [ k + 1 , j ] ; if ( oper [ k ] == ' & ' ) { T [ i , j ] += T [ i , k ] * T [ k + 1 , j ] ; F [ i , j ] += ( tik * tkj - T [ i , k ] * T [ k + 1 , j ] ) ; } if ( oper [ k ] == ' ▁ ' ) { F [ i , j ] += F [ i , k ] * F [ k + 1 , j ] ; T [ i , j ] += ( tik * tkj - F [ i , k ] * F [ k + 1 , j ] ) ; } if ( oper [ k ] == ' ^ ' ) { T [ i , j ] += F [ i , k ] * T [ k + 1 , j ] + T [ i , k ] * F [ k + 1 , j ] ; F [ i , j ] += T [ i , k ] * T [ k + 1 , j ] + F [ i , k ] * F [ k + 1 , j ] ; } } } } return T [ 0 , n - 1 ] ; } public static void Main ( ) { char [ ] symbols = " TTFT " . ToCharArray ( ) ; char [ ] operators = " | & ^ " . ToCharArray ( ) ; int n = symbols . Length ; Console . WriteLine ( countParenth ( symbols , operators , n ) ) ; } }

Index/key variables: i, k
Accumulator variables: g, i
Iterator variables: g, gap, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int countWays ( int N , string S ) { int [ , , ] dp = new int [ N + 1 , N + 1 , 2 ] ; for ( int i = 0 ; i < ( N + 1 ) ; i ++ ) { for ( int j = 0 ; j < ( N + 1 ) ; j ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) { dp [ i , j , k ] = - 1 ; } } } static int parenthesis_count ( string str , int i , int j , int isTrue , int [ , , ] dp ) { if ( i > j ) return 0 ; if ( i == j ) { if ( isTrue == 1 ) { return ( str [ i ] == ' T ' ) ? 1 : 0 ; } else { return ( str [ i ] == ' F ' ) ? 1 : 0 ; } } if ( dp [ i , j , isTrue ] != - 1 ) return dp [ i , j , isTrue ] ; int temp_ans = 0 ; int leftTrue , rightTrue , leftFalse , rightFalse ; for ( int k = i + 1 ; k <= j - 1 ; k = k + 2 ) { if ( dp [ i , k - 1 , 1 ] != - 1 ) leftTrue = dp [ i , k - 1 , 1 ] ; else { leftTrue = parenthesis_count ( str , i , k - 1 , 1 , dp ) ; } if ( dp [ i , k - 1 , 0 ] != - 1 ) leftFalse = dp [ i , k - 1 , 0 ] ; else { leftFalse = parenthesis_count ( str , i , k - 1 , 0 , dp ) ; } if ( dp [ k + 1 , j , 1 ] != - 1 ) rightTrue = dp [ k + 1 , j , 1 ] ; else { rightTrue = parenthesis_count ( str , k + 1 , j , 1 , dp ) ; } if ( dp [ k + 1 , j , 0 ] != - 1 ) rightFalse = dp [ k + 1 , j , 0 ] ; else { rightFalse = parenthesis_count ( str , k + 1 , j , 0 , dp ) ; } if ( str [ k ] == ' & ' ) { if ( isTrue == 1 ) { temp_ans = temp_ans + leftTrue * rightTrue ; } else { temp_ans = temp_ans + leftTrue * rightFalse + leftFalse * rightTrue + leftFalse * rightFalse ; } } else if ( str [ k ] == ' ▁ ' ) { if ( isTrue == 1 ) { temp_ans = temp_ans + leftTrue * rightTrue + leftTrue * rightFalse + leftFalse * rightTrue ; } else { temp_ans = temp_ans + leftFalse * rightFalse ; } } else if ( str [ k ] == ' ^ ' ) { if ( isTrue == 1 ) { temp_ans = temp_ans + leftTrue * rightFalse + leftFalse * rightTrue ; } else { temp_ans = temp_ans + leftTrue * rightTrue + leftFalse * rightFalse ; } } dp [ i , j , isTrue ] = temp_ans ; } return temp_ans ; } return parenthesis_count ( S , 0 , N - 1 , 1 , dp ) ; } static void Main ( ) { string symbols = " TTFT " ; string operators = " | & ^ " ; string S = " " ; int j = 0 ; for ( int i = 0 ; i < symbols . Length ; i ++ ) { S = S + symbols [ i ] ; if ( j < operators . Length ) S = S + operators [ j ++ ] ; } int N = S . Length ; Console . WriteLine ( countWays ( N , S ) ) ; } }

Index/key variables: i, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int getCount ( char [ , ] keypad , int n ) { if ( keypad == null n <= 0 ) return 0 ; if ( n == 1 ) return 10 ; int [ ] row = { 0 , 0 , - 1 , 0 , 1 } ; int [ ] col = { 0 , - 1 , 0 , 1 , 0 } ; int [ , ] count = new int [ 10 , n + 1 ] ; int i = 0 , j = 0 , k = 0 , move = 0 , ro = 0 , co = 0 , num = 0 ; int nextNum = 0 , totalCount = 0 ; for ( i = 0 ; i <= 9 ; i ++ ) { count [ i , 0 ] = 0 ; count [ i , 1 ] = 1 ; } for ( k = 2 ; k <= n ; k ++ ) { for ( i = 0 ; i < 4 ; i ++ ) { for ( j = 0 ; j < 3 ; j ++ ) { if ( keypad [ i , j ] != ' * ' && keypad [ i , j ] != ' # ' ) { num = keypad [ i , j ] - '0' ; count [ num , k ] = 0 ; for ( move = 0 ; move < 5 ; move ++ ) { ro = i + row [ move ] ; co = j + col [ move ] ; if ( ro >= 0 && ro <= 3 && co >= 0 && co <= 2 && keypad [ ro , co ] != ' * ' && keypad [ ro , co ] != ' # ' ) { nextNum = keypad [ ro , co ] - '0' ; count [ num , k ] += count [ nextNum , k - 1 ] ; } } } } } } totalCount = 0 ; for ( i = 0 ; i <= 9 ; i ++ ) totalCount += count [ i , n ] ; return totalCount ; } public static void Main ( String [ ] args ) { char [ , ] keypad = { { '1' , '2' , '3' } , { '4' , '5' , '6' } , { '7' , '8' , '9' } , { ' * ' , '0' , ' # ' } } ; Console . Write ( " Count ▁ for ▁ numbers ▁ of . Length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 1 , getCount ( keypad , 1 ) ) ; Console . Write ( " Count ▁ for ▁ numbers ▁ of . Length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 2 , getCount ( keypad , 2 ) ) ; Console . Write ( " Count ▁ for ▁ numbers ▁ of . Length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 3 , getCount ( keypad , 3 ) ) ; Console . Write ( " Count ▁ for ▁ numbers ▁ of . Length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 4 , getCount ( keypad , 4 ) ) ; Console . Write ( " Count ▁ for ▁ numbers ▁ of . Length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 5 , getCount ( keypad , 5 ) ) ; } }

Index/key variables: move
Accumulator variables: i, j, k, move, totalCount
Iterator variables: i, j, k, move
Class/struct names: GFG
C# program:
using System ; class GFG { static int getCount ( char [ , ] keypad , int n ) { if ( keypad == null n <= 0 ) return 0 ; if ( n == 1 ) return 10 ; int [ ] odd = new int [ 10 ] ; int [ ] even = new int [ 10 ] ; int i = 0 , j = 0 , useOdd = 0 , totalCount = 0 ; for ( i = 0 ; i <= 9 ; i ++ ) odd [ i ] = 1 ; for ( j = 2 ; j <= n ; j ++ ) { useOdd = 1 - useOdd ; if ( useOdd == 1 ) { even [ 0 ] = odd [ 0 ] + odd [ 8 ] ; even [ 1 ] = odd [ 1 ] + odd [ 2 ] + odd [ 4 ] ; even [ 2 ] = odd [ 2 ] + odd [ 1 ] + odd [ 3 ] + odd [ 5 ] ; even [ 3 ] = odd [ 3 ] + odd [ 2 ] + odd [ 6 ] ; even [ 4 ] = odd [ 4 ] + odd [ 1 ] + odd [ 5 ] + odd [ 7 ] ; even [ 5 ] = odd [ 5 ] + odd [ 2 ] + odd [ 4 ] + odd [ 8 ] + odd [ 6 ] ; even [ 6 ] = odd [ 6 ] + odd [ 3 ] + odd [ 5 ] + odd [ 9 ] ; even [ 7 ] = odd [ 7 ] + odd [ 4 ] + odd [ 8 ] ; even [ 8 ] = odd [ 8 ] + odd [ 0 ] + odd [ 5 ] + odd [ 7 ] + odd [ 9 ] ; even [ 9 ] = odd [ 9 ] + odd [ 6 ] + odd [ 8 ] ; } else { odd [ 0 ] = even [ 0 ] + even [ 8 ] ; odd [ 1 ] = even [ 1 ] + even [ 2 ] + even [ 4 ] ; odd [ 2 ] = even [ 2 ] + even [ 1 ] + even [ 3 ] + even [ 5 ] ; odd [ 3 ] = even [ 3 ] + even [ 2 ] + even [ 6 ] ; odd [ 4 ] = even [ 4 ] + even [ 1 ] + even [ 5 ] + even [ 7 ] ; odd [ 5 ] = even [ 5 ] + even [ 2 ] + even [ 4 ] + even [ 8 ] + even [ 6 ] ; odd [ 6 ] = even [ 6 ] + even [ 3 ] + even [ 5 ] + even [ 9 ] ; odd [ 7 ] = even [ 7 ] + even [ 4 ] + even [ 8 ] ; odd [ 8 ] = even [ 8 ] + even [ 0 ] + even [ 5 ] + even [ 7 ] + even [ 9 ] ; odd [ 9 ] = even [ 9 ] + even [ 6 ] + even [ 8 ] ; } } totalCount = 0 ; if ( useOdd == 1 ) { for ( i = 0 ; i <= 9 ; i ++ ) totalCount += even [ i ] ; } else { for ( i = 0 ; i <= 9 ; i ++ ) totalCount += odd [ i ] ; } return totalCount ; } public static void Main ( String [ ] args ) { char [ , ] keypad = { { '1' , '2' , '3' } , { '4' , '5' , '6' } , { '7' , '8' , '9' } , { ' * ' , '0' , ' # ' } } ; Console . Write ( " Count ▁ for ▁ numbers ▁ of ▁ length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 1 , getCount ( keypad , 1 ) ) ; Console . Write ( " Count ▁ for ▁ numbers ▁ of ▁ length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 2 , getCount ( keypad , 2 ) ) ; Console . Write ( " Count ▁ for ▁ numbers ▁ of ▁ length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 3 , getCount ( keypad , 3 ) ) ; Console . Write ( " Count ▁ for ▁ numbers ▁ of ▁ length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 4 , getCount ( keypad , 4 ) ) ; Console . Write ( " Count ▁ for ▁ numbers ▁ of ▁ length ▁ { 0 } : ▁ { 1 } STRNEWLINE " , 5 , getCount ( keypad , 5 ) ) ; } }

Index/key variables: i
Accumulator variables: i, j, totalCount
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countRec ( int n , int sum ) { if ( n == 0 ) return sum == 0 ? 1 : 0 ; if ( sum == 0 ) return 1 ; int ans = 0 ; for ( int i = 0 ; i <= 9 ; i ++ ) if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; return ans ; } static int finalCount ( int n , int sum ) { int ans = 0 ; for ( int i = 1 ; i <= 9 ; i ++ ) if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; return ans ; } public static void Main ( ) { int n = 2 , sum = 5 ; Console . Write ( finalCount ( n , sum ) ) ; } }

Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class sum_dig { static int [ , ] lookup = new int [ 101 , 501 ] ; static int countRec ( int n , int sum ) { if ( n == 0 ) return sum == 0 ? 1 : 0 ; if ( lookup [ n , sum ] != - 1 ) return lookup [ n , sum ] ; int ans = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; return lookup [ n , sum ] = ans ; } static int finalCount ( int n , int sum ) { for ( int i = 0 ; i <= 100 ; ++ i ) { for ( int j = 0 ; j <= 500 ; ++ j ) { lookup [ i , j ] = - 1 ; } } int ans = 0 ; for ( int i = 1 ; i <= 9 ; i ++ ) if ( sum - i >= 0 ) ans += countRec ( n - 1 , sum - i ) ; return ans ; } public static void Main ( ) { int n = 3 , sum = 5 ; Console . Write ( finalCount ( n , sum ) ) ; } }

Accumulator variables: ans, i
Iterator variables: i, j
Class/struct names: sum_dig
C# program:
using System ; class GFG { private static void findCount ( int n , int sum ) { int start = ( int ) Math . Pow ( 10 , n - 1 ) ; int end = ( int ) Math . Pow ( 10 , n ) - 1 ; int count = 0 ; int i = start ; while ( i < end ) { int cur = 0 ; int temp = i ; while ( temp != 0 ) { cur += temp % 10 ; temp = temp / 10 ; } if ( cur == sum ) { count ++ ; i += 9 ; } else i ++ ; } Console . WriteLine ( count ) ; } public static void Main ( ) { int n = 3 ; int sum = 5 ; findCount ( n , sum ) ; } }

Accumulator variables: count, cur, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int getMinSquares ( int n ) { if ( n <= 3 ) return n ; int res = n ; for ( int x = 1 ; x <= n ; x ++ ) { int temp = x * x ; if ( temp > n ) break ; else res = Math . Min ( res , 1 + getMinSquares ( n - temp ) ) ; } return res ; } public static void Main ( ) { Console . Write ( getMinSquares ( 6 ) ) ; } }

Accumulator variables: x
Iterator variables: x
Class/struct names: GFG
C# program:
using System ; class squares { static int getMinSquares ( int n ) { if ( n <= 3 ) return n ; int [ ] dp = new int [ n + 1 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; dp [ 2 ] = 2 ; dp [ 3 ] = 3 ; for ( int i = 4 ; i <= n ; i ++ ) { dp [ i ] = i ; for ( int x = 1 ; x <= Math . Ceiling ( Math . Sqrt ( i ) ) ; x ++ ) { int temp = x * x ; if ( temp > i ) break ; else dp [ i ] = Math . Min ( dp [ i ] , 1 + dp [ i - temp ] ) ; } } int res = dp [ n ] ; return res ; } public static void Main ( String [ ] args ) { Console . Write ( getMinSquares ( 6 ) ) ; } }

Index/key variables: i, n
Accumulator variables: i, x
Iterator variables: i, x
Class/struct names: squares
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { public class Point { public int x , y ; public Point ( int x , int y ) { this . x = x ; this . y = y ; } } public static int numSquares ( int n ) { int [ ] visited = new int [ n + 1 ] ; Queue q = new Queue ( ) ; int ans = 1000000000 ; q . Enqueue ( new Point ( n , 0 ) ) ; visited [ n ] = 1 ; while ( q . Count != 0 ) { Point p = ( Point ) q . Dequeue ( ) ; if ( p . x == 0 ) ans = Math . Min ( ans , p . y ) ; for ( int i = 1 ; i * i <= p . x ; i ++ ) { int path = ( p . x - ( i * i ) ) ; if ( path >= 0 && ( visited [ path ] == 0 path == 0 ) ) { visited [ path ] = 1 ; q . Enqueue ( new Point ( path , p . y + 1 ) ) ; } } } return ans ; } public static void Main ( string [ ] args ) { Console . Write ( numSquares ( 12 ) ) ; } }

Index/key variables: n, path
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Point
C# program:
using System ; class coin { static int minCoins ( int [ ] coins , int m , int V ) { if ( V == 0 ) return 0 ; int res = int . MaxValue ; for ( int i = 0 ; i < m ; i ++ ) { if ( coins [ i ] <= V ) { int sub_res = minCoins ( coins , m , V - coins [ i ] ) ; if ( sub_res != int . MaxValue && sub_res + 1 < res ) res = sub_res + 1 ; } } return res ; } public static void Main ( ) { int [ ] coins = { 9 , 6 , 5 , 1 } ; int m = coins . Length ; int V = 11 ; Console . Write ( " Minimum ▁ coins ▁ required ▁ is ▁ " + minCoins ( coins , m , V ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: coin
C# program:
using System ; class GFG { static int minCoins ( int [ ] coins , int m , int V ) { int [ ] table = new int [ V + 1 ] ; table [ 0 ] = 0 ; for ( int i = 1 ; i <= V ; i ++ ) table [ i ] = int . MaxValue ; for ( int i = 1 ; i <= V ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) if ( coins [ j ] <= i ) { int sub_res = table [ i - coins [ j ] ] ; if ( sub_res != int . MaxValue && sub_res + 1 < table [ i ] ) table [ i ] = sub_res + 1 ; } } return table [ V ] ; } static public void Main ( ) { int [ ] coins = { 9 , 6 , 5 , 1 } ; int m = coins . Length ; int V = 11 ; Console . WriteLine ( " Minimum ▁ coins ▁ required ▁ is ▁ " + minCoins ( coins , m , V ) ) ; } }

Index/key variables: V, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int superSeq ( String X , String Y , int m , int n ) { if ( m == 0 ) return n ; if ( n == 0 ) return m ; if ( X [ m - 1 ] == Y [ n - 1 ] ) return 1 + superSeq ( X , Y , m - 1 , n - 1 ) ; return 1 + Math . Min ( superSeq ( X , Y , m - 1 , n ) , superSeq ( X , Y , m , n - 1 ) ) ; } public static void Main ( ) { String X = " AGGTAB " ; String Y = " GXTXAYB " ; Console . WriteLine ( " Length ▁ of ▁ the ▁ shortest ▁ supersequence ▁ is : ▁ " + superSeq ( X , Y , X . Length , Y . Length ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int superSeq ( String X , String Y , int m , int n ) { 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 ( X [ i - 1 ] == Y [ 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 ] ) ; } } return dp [ m , n ] ; } public static void Main ( ) { String X = " AGGTAB " ; String Y = " GXTXAYB " ; Console . WriteLine ( " Length ▁ of ▁ the ▁ shortest ▁ supersequence ▁ is ▁ " + superSeq ( X , Y , X . Length , Y . Length ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static int sumOfDigitsFrom1ToN ( int n ) { int result = 0 ; for ( int x = 1 ; x <= n ; x ++ ) result += sumOfDigits ( x ) ; return result ; } static int sumOfDigits ( int x ) { int sum = 0 ; while ( x != 0 ) { sum += x % 10 ; x = x / 10 ; } return sum ; } public static void Main ( ) { int n = 328 ; Console . WriteLine ( " Sum ▁ of ▁ digits " + " ▁ in ▁ numbers ▁ from ▁ 1 ▁ to ▁ " + n + " ▁ is ▁ " + sumOfDigitsFrom1ToN ( n ) ) ; } }

Accumulator variables: result, sum, x
Iterator variables: x
Class/struct names: GFG
C# program:
using System ; public class GFG { static int sumOfDigitsFrom1ToN ( int n ) { if ( n < 10 ) return ( n * ( n + 1 ) / 2 ) ; int d = ( int ) ( Math . Log ( n ) / Math . Log ( 10 ) ) ; int [ ] a = new int [ d + 1 ] ; a [ 0 ] = 0 ; a [ 1 ] = 45 ; for ( int i = 2 ; i <= d ; i ++ ) a [ i ] = a [ i - 1 ] * 10 + 45 * ( int ) ( Math . Ceiling ( Math . Pow ( 10 , i - 1 ) ) ) ; int p = ( int ) ( Math . Ceiling ( Math . Pow ( 10 , d ) ) ) ; int msd = n / p ; return ( msd * a [ d ] + ( msd * ( msd - 1 ) / 2 ) * p + msd * ( 1 + n % p ) + sumOfDigitsFrom1ToN ( n % p ) ) ; } public static void Main ( ) { int n = 328 ; Console . WriteLine ( " Sum ▁ of ▁ digits ▁ in ▁ numbers ▁ " + " from ▁ 1 ▁ to ▁ " + n + " ▁ is ▁ " + sumOfDigitsFrom1ToN ( n ) ) ; } }

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