dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int ROW = 4 ; static int COL = 5 ; static void findUniqueRows ( int [ , ] M ) { for ( int i = 0 ; i < ROW ; i ++ ) { int flag = 0 ; for ( int j = 0 ; j < i ; j ++ ) { flag = 1 ; for ( int k = 0 ; k < COL ; k ++ ) if ( M [ i , k ] != M [ j , k ] ) flag = 0 ; if ( flag == 1 ) break ; } if ( flag == 0 ) { for ( int j = 0 ; j < COL ; j ++ ) Console . Write ( M [ i , j ] + " ▁ " ) ; Console . WriteLine ( ) ; } } } static void Main ( ) { int [ , ] M = { { 0 , 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 1 , 0 } , { 0 , 1 , 0 , 0 , 1 } , { 1 , 0 , 1 , 0 , 0 } } ; findUniqueRows ( M ) ; } }

Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { public static void printArray ( int [ ] [ ] arr , int row , int col ) { HashSet < string > set = new HashSet < string > ( ) ; for ( int i = 0 ; i < row ; i ++ ) { string s = " " ; for ( int j = 0 ; j < col ; j ++ ) { s += arr [ i ] [ j ] . ToString ( ) ; } if ( ! set . Contains ( s ) ) { set . Add ( s ) ; Console . WriteLine ( s ) ; } } } public static void Main ( string [ ] args ) { int [ ] [ ] arr = new int [ ] [ ] { new int [ ] { 0 , 1 , 0 , 0 , 1 } , new int [ ] { 1 , 0 , 1 , 1 , 0 } , new int [ ] { 0 , 1 , 0 , 0 , 1 } , new int [ ] { 1 , 1 , 1 , 0 , 0 } } ; printArray ( arr , 4 , 5 ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, s
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static readonly int R = 3 ; static readonly int C = 5 ; static int maxArea ( int [ , ] mat ) { int [ , ] hist = new int [ R + 1 , C + 1 ] ; for ( int i = 0 ; i < C ; i ++ ) { hist [ 0 , i ] = mat [ 0 , i ] ; for ( int j = 1 ; j < R ; j ++ ) { hist [ j , i ] = ( mat [ j , i ] == 0 ) ? 0 : hist [ j - 1 , i ] + 1 ; } } for ( int i = 0 ; i < R ; i ++ ) { int [ ] count = new int [ R + 1 ] ; for ( int j = 0 ; j < C ; j ++ ) { count [ hist [ i , j ] ] ++ ; } int col_no = 0 ; for ( int j = R ; j >= 0 ; j -- ) { if ( count [ j ] > 0 ) { for ( int k = 0 ; k < count [ j ] ; k ++ ) { hist [ i , col_no ] = j ; col_no ++ ; } } } } int curr_area , max_area = 0 ; for ( int i = 0 ; i < R ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { curr_area = ( j + 1 ) * hist [ i , j ] ; if ( curr_area > max_area ) { max_area = curr_area ; } } } return max_area ; } public static void Main ( ) { int [ , ] mat = { { 0 , 1 , 0 , 1 , 0 } , { 0 , 1 , 0 , 1 , 1 } , { 1 , 1 , 0 , 1 , 0 } } ; Console . WriteLine ( " Area ▁ of ▁ the ▁ largest ▁ rectangle ▁ is ▁ " + maxArea ( mat ) ) ; } }

Index/key variables: j
Accumulator variables: col_no, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int M = 4 ; static int N = 5 ; static int preProcess ( int [ , ] mat , int [ , ] aux ) { for ( int i = 0 ; i < N ; i ++ ) aux [ 0 , i ] = mat [ 0 , i ] ; for ( int i = 1 ; i < M ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) aux [ i , j ] = mat [ i , j ] + aux [ i - 1 , j ] ; for ( int i = 0 ; i < M ; i ++ ) for ( int j = 1 ; j < N ; j ++ ) aux [ i , j ] += aux [ i , j - 1 ] ; return 0 ; } static int sumQuery ( int [ , ] aux , int tli , int tlj , int rbi , int rbj ) { int res = aux [ rbi , rbj ] ; if ( tli > 0 ) res = res - aux [ tli - 1 , rbj ] ; if ( tlj > 0 ) res = res - aux [ rbi , tlj - 1 ] ; if ( tli > 0 && tlj > 0 ) res = res + aux [ tli - 1 , tlj - 1 ] ; return res ; } public static void Main ( ) { int [ , ] mat = { { 1 , 2 , 3 , 4 , 6 } , { 5 , 3 , 8 , 1 , 2 } , { 4 , 6 , 7 , 5 , 5 } , { 2 , 4 , 8 , 9 , 4 } } ; int [ , ] aux = new int [ M , N ] ; preProcess ( mat , aux ) ; int tli = 2 , tlj = 2 , rbi = 3 , rbj = 4 ; Console . Write ( " Query1 : " sumQuery ( aux , tli , tlj , rbi , rbj ) ) ; tli = 0 ; tlj = 0 ; rbi = 1 ; rbj = 1 ; Console . Write ( " Query2 : " sumQuery ( aux , tli , tlj , rbi , rbj ) ) ; tli = 1 ; tlj = 2 ; rbi = 3 ; rbj = 3 ; Console . Write ( " Query3 : " sumQuery ( aux , tli , tlj , rbi , rbj ) ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int R = 3 ; static int C = 3 ; static void swap ( int [ , ] mat , int row1 , int row2 , int col ) { for ( int i = 0 ; i < col ; i ++ ) { int temp = mat [ row1 , i ] ; mat [ row1 , i ] = mat [ row2 , i ] ; mat [ row2 , i ] = temp ; } } static int rankOfMatrix ( int [ , ] mat ) { int rank = C ; for ( int row = 0 ; row < rank ; row ++ ) { if ( mat [ row , row ] != 0 ) { for ( int col = 0 ; col < R ; col ++ ) { if ( col != row ) { double mult = ( double ) mat [ col , row ] / mat [ row , row ] ; for ( int i = 0 ; i < rank ; i ++ ) mat [ col , i ] -= ( int ) mult * mat [ row , i ] ; } } } else { bool reduce = true ; for ( int i = row + 1 ; i < R ; i ++ ) { if ( mat [ i , row ] != 0 ) { swap ( mat , row , i , rank ) ; reduce = false ; break ; } } if ( reduce ) { rank -- ; for ( int i = 0 ; i < R ; i ++ ) mat [ i , row ] = mat [ i , rank ] ; } row -- ; } } return rank ; } static void display ( int [ , ] mat , int row , int col ) { for ( int i = 0 ; i < row ; i ++ ) { for ( int j = 0 ; j < col ; j ++ ) Console . Write ( " ▁ " + mat [ i , j ] ) ; Console . Write ( " STRNEWLINE " ) ; } } public static void Main ( ) { int [ , ] mat = { { 10 , 20 , 10 } , { - 20 , - 30 , 10 } , { 30 , 50 , 0 } } ; Console . Write ( " Rank ▁ of ▁ the ▁ matrix ▁ is ▁ : ▁ " + rankOfMatrix ( mat ) ) ; } }

Accumulator variables: col, i, j, rank, row
Iterator variables: col, i, j, row
Boolean variables: reduce
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { public static int maxHist ( int R , int C , int [ ] row ) { Stack < int > result = new Stack < int > ( ) ; int top_val ; int max_area = 0 ; int area = 0 ; int i = 0 ; while ( i < C ) { if ( result . Count == 0 || row [ result . Peek ( ) ] <= row [ i ] ) { result . Push ( i ++ ) ; } else { top_val = row [ result . Peek ( ) ] ; result . Pop ( ) ; area = top_val * i ; if ( result . Count > 0 ) { area = top_val * ( i - result . Peek ( ) - 1 ) ; } max_area = Math . Max ( area , max_area ) ; } } while ( result . Count > 0 ) { top_val = row [ result . Peek ( ) ] ; result . Pop ( ) ; area = top_val * i ; if ( result . Count > 0 ) { area = top_val * ( i - result . Peek ( ) - 1 ) ; } max_area = Math . Max ( area , max_area ) ; } return max_area ; } public static int maxRectangle ( int R , int C , int [ ] [ ] A ) { int result = maxHist ( R , C , A [ 0 ] ) ; for ( int i = 1 ; i < R ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( A [ i ] [ j ] == 1 ) { A [ i ] [ j ] += A [ i - 1 ] [ j ] ; } } result = Math . Max ( result , maxHist ( R , C , A [ i ] ) ) ; } return result ; } public static void Main ( string [ ] args ) { int R = 4 ; int C = 4 ; int [ ] [ ] A = new int [ ] [ ] { new int [ ] { 0 , 1 , 1 , 0 } , new int [ ] { 1 , 1 , 1 , 1 } , new int [ ] { 1 , 1 , 1 , 1 } , new int [ ] { 1 , 1 , 0 , 0 } } ; Console . Write ( " Area ▁ of ▁ maximum ▁ rectangle ▁ is ▁ " + maxRectangle ( R , C , A ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int R = 3 ; static int C = 3 ; public class Cell { public int r ; public int c ; public Cell ( int r , int c ) { this . r = r ; this . c = c ; } } ; static void printSums ( int [ , ] mat , Cell [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 , r = arr [ i ] . r , c = arr [ i ] . c ; for ( int j = 0 ; j < R ; j ++ ) { for ( int k = 0 ; k < C ; k ++ ) { if ( j != r && k != c ) { sum += mat [ j , k ] ; } } } Console . WriteLine ( sum ) ; } } public static void Main ( String [ ] args ) { int [ , ] mat = { { 1 , 1 , 2 } , { 3 , 4 , 6 } , { 5 , 3 , 2 } } ; Cell [ ] arr = { new Cell ( 0 , 0 ) , new Cell ( 1 , 1 ) , new Cell ( 0 , 1 ) } ; int n = arr . Length ; printSums ( mat , arr , n ) ; } }

Index/key variables: i
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Class/struct names: Cell, GFG
C# program:
using System ; class GFG { static int R = 3 ; static int C = 3 ; public class Cell { public int r ; public int c ; public Cell ( int r , int c ) { this . r = r ; this . c = c ; } } ; static void printSums ( int [ , ] mat , Cell [ ] arr , int n ) { int sum = 0 ; int [ ] row = new int [ R ] ; int [ ] col = new int [ C ] ; for ( int i = 0 ; i < R ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { sum += mat [ i , j ] ; col [ j ] += mat [ i , j ] ; row [ i ] += mat [ i , j ] ; } } for ( int i = 0 ; i < n ; i ++ ) { int ro = arr [ i ] . r , co = arr [ i ] . c ; Console . WriteLine ( sum - row [ ro ] - col [ co ] + mat [ ro , co ] ) ; } } public static void Main ( String [ ] args ) { int [ , ] mat = { { 1 , 1 , 2 } , { 3 , 4 , 6 } , { 5 , 3 , 2 } } ; Cell [ ] arr = { new Cell ( 0 , 0 ) , new Cell ( 1 , 1 ) , new Cell ( 0 , 1 ) } ; int n = arr . Length ; printSums ( mat , arr , n ) ; } }

Index/key variables: C, R, co, i, j, ro
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: Cell, GFG
C# program:
using System ; class GFG { static int countIslands ( int [ , ] mat , int m , int n ) { int count = 0 ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( mat [ i , j ] == ' X ' ) { if ( ( i == 0 mat [ i - 1 , j ] == ' O ' ) && ( j == 0 mat [ i , j - 1 ] == ' O ' ) ) count ++ ; } } } return count ; } public static void Main ( ) { int m = 6 ; int n = 3 ; int [ , ] mat = { { ' O ' , ' O ' , ' O ' } , { ' X ' , ' X ' , ' O ' } , { ' X ' , ' X ' , ' O ' } , { ' O ' , ' O ' , ' X ' } , { ' O ' , ' O ' , ' X ' } , { ' X ' , ' X ' , ' O ' } } ; Console . WriteLine ( " Number ▁ of ▁ rectangular ▁ " + " islands ▁ is : ▁ " + countIslands ( mat , m , n ) ) ; } }

Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int M = 4 ; static int N = 5 ; static int findCommon ( int [ , ] mat ) { int [ ] column = new int [ M ] ; int min_row ; int i ; for ( i = 0 ; i < M ; i ++ ) column [ i ] = N - 1 ; min_row = 0 ; while ( column [ min_row ] >= 0 ) { for ( i = 0 ; i < M ; i ++ ) { if ( mat [ i , column [ i ] ] < mat [ min_row , column [ min_row ] ] ) min_row = i ; } int eq_count = 0 ; for ( i = 0 ; i < M ; i ++ ) { if ( mat [ i , column [ i ] ] > mat [ min_row , column [ min_row ] ] ) { if ( column [ i ] == 0 ) return - 1 ; column [ i ] -= 1 ; } else eq_count ++ ; } if ( eq_count == M ) return mat [ min_row , column [ min_row ] ] ; } return - 1 ; } public static void Main ( ) { int [ , ] mat = { { 1 , 2 , 3 , 4 , 5 } , { 2 , 4 , 5 , 8 , 10 } , { 3 , 5 , 7 , 9 , 11 } , { 1 , 3 , 5 , 7 , 9 } } ; int result = findCommon ( mat ) ; if ( result == - 1 ) Console . Write ( " No ▁ common ▁ element " ) ; else Console . Write ( " Common ▁ element ▁ is ▁ " + result ) ; } }

Index/key variables: M, i, min_row
Accumulator variables: eq_count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int M = 4 ; static int N = 5 ; static int findCommon ( int [ , ] mat ) { Dictionary < int , int > cnt = new Dictionary < int , int > ( ) ; int i , j ; for ( i = 0 ; i < M ; i ++ ) { if ( cnt . ContainsKey ( mat [ i , 0 ] ) ) { cnt [ mat [ i , 0 ] ] = cnt [ mat [ i , 0 ] ] + 1 ; } else { cnt . Add ( mat [ i , 0 ] , 1 ) ; } for ( j = 1 ; j < N ; j ++ ) { if ( mat [ i , j ] != mat [ i , j - 1 ] ) if ( cnt . ContainsKey ( mat [ i , j ] ) ) { cnt [ mat [ i , j ] ] = cnt [ mat [ i , j ] ] + 1 ; } else { cnt . Add ( mat [ i , j ] , 1 ) ; } } } foreach ( KeyValuePair < int , int > ele in cnt ) { if ( ele . Value == M ) return ele . Key ; } return - 1 ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 1 , 2 , 3 , 4 , 5 } , { 2 , 4 , 5 , 8 , 10 } , { 3 , 5 , 7 , 9 , 11 } , { 1 , 3 , 5 , 7 , 9 } } ; int result = findCommon ( mat ) ; if ( result == - 1 ) Console . WriteLine ( " No ▁ common ▁ element " ) ; else Console . WriteLine ( " Common ▁ element ▁ is ▁ " + result ) ; } }

Accumulator variables: i, j
Iterator variables: ele, i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int M = 6 ; static int N = 6 ; static void floodFillUtil ( char [ , ] mat , int x , int y , char prevV , char newV ) { if ( x < 0 x >= M y < 0 y >= N ) return ; if ( mat [ x , y ] != prevV ) return ; mat [ x , y ] = newV ; floodFillUtil ( mat , x + 1 , y , prevV , newV ) ; floodFillUtil ( mat , x - 1 , y , prevV , newV ) ; floodFillUtil ( mat , x , y + 1 , prevV , newV ) ; floodFillUtil ( mat , x , y - 1 , prevV , newV ) ; } static void replaceSurrounded ( char [ , ] mat ) { for ( int i = 0 ; i < M ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) if ( mat [ i , j ] == ' O ' ) mat [ i , j ] = ' - ' ; for ( int i = 0 ; i < M ; i ++ ) if ( mat [ i , 0 ] == ' - ' ) floodFillUtil ( mat , i , 0 , ' - ' , ' O ' ) ; for ( int i = 0 ; i < M ; i ++ ) if ( mat [ i , N - 1 ] == ' - ' ) floodFillUtil ( mat , i , N - 1 , ' - ' , ' O ' ) ; for ( int i = 0 ; i < N ; i ++ ) if ( mat [ 0 , i ] == ' - ' ) floodFillUtil ( mat , 0 , i , ' - ' , ' O ' ) ; for ( int i = 0 ; i < N ; i ++ ) if ( mat [ M - 1 , i ] == ' - ' ) floodFillUtil ( mat , M - 1 , i , ' - ' , ' O ' ) ; for ( int i = 0 ; i < M ; i ++ ) for ( int j = 0 ; j < N ; j ++ ) if ( mat [ i , j ] == ' - ' ) mat [ i , j ] = ' X ' ; } public static void Main ( ) { char [ , ] mat = new char [ , ] { { ' X ' , ' O ' , ' X ' , ' O ' , ' X ' , ' X ' } , { ' X ' , ' O ' , ' X ' , ' X ' , ' O ' , ' X ' } , { ' X ' , ' X ' , ' X ' , ' O ' , ' X ' , ' X ' } , { ' O ' , ' X ' , ' X ' , ' X ' , ' X ' , ' X ' } , { ' X ' , ' X ' , ' X ' , ' O ' , ' X ' , ' O ' } , { ' O ' , ' O ' , ' X ' , ' O ' , ' O ' , ' O ' } } ; replaceSurrounded ( mat ) ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) Console . Write ( mat [ i , j ] + " ▁ " ) ; Console . WriteLine ( " " ) ; } } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public class node { public int data ; public node left , right ; public node ( int data ) { this . data = data ; } } public static node prev ; public static void inorder ( node root ) { if ( root == null ) { return ; } inorder ( root . left ) ; Console . Write ( root . data + " ▁ " ) ; inorder ( root . right ) ; } public static void fixPrevptr ( node root ) { if ( root == null ) { return ; } fixPrevptr ( root . left ) ; root . left = prev ; prev = root ; fixPrevptr ( root . right ) ; } public static node fixNextptr ( node root ) { while ( root . right != null ) { root = root . right ; } while ( root != null && root . left != null ) { node left = root . left ; left . right = root ; root = root . left ; } return root ; } public static node BTTtoDLL ( node root ) { prev = null ; fixPrevptr ( root ) ; return fixNextptr ( root ) ; } public static void printlist ( node root ) { while ( root != null ) { Console . Write ( root . data + " ▁ " ) ; root = root . right ; } } public static void Main ( ) { node root = new node ( 10 ) ; root . left = new node ( 12 ) ; root . right = new node ( 15 ) ; root . left . left = new node ( 25 ) ; root . left . right = new node ( 30 ) ; root . right . left = new node ( 36 ) ; Console . WriteLine ( " Inorder ▁ Tree ▁ Traversal " ) ; inorder ( root ) ; node head = BTTtoDLL ( root ) ; Console . WriteLine ( " STRNEWLINE DLL ▁ Traversal " ) ; printlist ( head ) ; } }

Class/struct names: GFG, node
C# program:
using System ; public class Node { public int data ; public Node left , right ; public Node ( int data ) { this . data = data ; left = right = null ; } } class GFG { public Node root ; public Node head ; public virtual void BinaryTree2DoubleLinkedList ( Node root ) { if ( root == null ) { return ; } public static Node prev = null ; BinaryTree2DoubleLinkedList ( root . left ) ; if ( prev == null ) { head = root ; } else { root . left = prev ; prev . right = root ; } prev = root ; BinaryTree2DoubleLinkedList ( root . right ) ; } public virtual void printList ( Node node ) { while ( node != null ) { Console . Write ( node . data + " ▁ " ) ; node = node . right ; } } public static void Main ( string [ ] args ) { GFG tree = new GFG ( ) ; tree . root = new Node ( 10 ) ; tree . root . left = new Node ( 12 ) ; tree . root . right = new Node ( 15 ) ; tree . root . left . left = new Node ( 25 ) ; tree . root . left . right = new Node ( 30 ) ; tree . root . right . left = new Node ( 36 ) ; tree . BinaryTree2DoubleLinkedList ( tree . root ) ; tree . printList ( tree . head ) ; } }

Class/struct names: GFG, Node
C# program:
using System ; class GFG { static readonly int R = 5 ; static readonly int C = 4 ; static bool isValid ( int x , int y1 , int y2 ) { return ( x >= 0 && x < R && y1 >= 0 && y1 < C && y2 >= 0 && y2 < C ) ; } static int getMaxUtil ( int [ , ] arr , int [ , , ] mem , int x , int y1 , int y2 ) { if ( ! isValid ( x , y1 , y2 ) ) return int . MinValue ; if ( x == R - 1 && y1 == 0 && y2 == C - 1 ) return ( y1 == y2 ) ? arr [ x , y1 ] : arr [ x , y1 ] + arr [ x , y2 ] ; if ( x == R - 1 ) return int . MinValue ; if ( mem [ x , y1 , y2 ] != - 1 ) return mem [ x , y1 , y2 ] ; int ans = int . MinValue ; int temp = ( y1 == y2 ) ? arr [ x , y1 ] : arr [ x , y1 ] + arr [ x , y2 ] ; ans = Math . Max ( ans , temp + getMaxUtil ( arr , mem , x + 1 , y1 , y2 - 1 ) ) ; ans = Math . Max ( ans , temp + getMaxUtil ( arr , mem , x + 1 , y1 , y2 + 1 ) ) ; ans = Math . Max ( ans , temp + getMaxUtil ( arr , mem , x + 1 , y1 , y2 ) ) ; ans = Math . Max ( ans , temp + getMaxUtil ( arr , mem , x + 1 , y1 - 1 , y2 ) ) ; ans = Math . Max ( ans , temp + getMaxUtil ( arr , mem , x + 1 , y1 - 1 , y2 - 1 ) ) ; ans = Math . Max ( ans , temp + getMaxUtil ( arr , mem , x + 1 , y1 - 1 , y2 + 1 ) ) ; ans = Math . Max ( ans , temp + getMaxUtil ( arr , mem , x + 1 , y1 + 1 , y2 ) ) ; ans = Math . Max ( ans , temp + getMaxUtil ( arr , mem , x + 1 , y1 + 1 , y2 - 1 ) ) ; ans = Math . Max ( ans , temp + getMaxUtil ( arr , mem , x + 1 , y1 + 1 , y2 + 1 ) ) ; return ( mem [ x , y1 , y2 ] = ans ) ; } static int geMaxCollection ( int [ , ] arr ) { int [ , , ] mem = new int [ R , C , C ] ; for ( int i = 0 ; i < R ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { for ( int l = 0 ; l < C ; l ++ ) mem [ i , j , l ] = - 1 ; } } return getMaxUtil ( arr , mem , 0 , 0 , C - 1 ) ; } public static void Main ( String [ ] args ) { int [ , ] arr = { { 3 , 6 , 8 , 2 } , { 5 , 2 , 4 , 3 } , { 1 , 1 , 20 , 10 } , { 1 , 1 , 20 , 10 } , { 1 , 1 , 20 , 10 } , } ; Console . Write ( " Maximum ▁ collection ▁ is ▁ " + geMaxCollection ( arr ) ) ; } }

Accumulator variables: i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
C# program:
using System ; class GFG { static int [ ] x = { 0 , 1 , 1 , - 1 , 1 , 0 , - 1 , - 1 } ; static int [ ] y = { 1 , 0 , 1 , 1 , - 1 , - 1 , 0 , - 1 } ; static int R = 3 ; static int C = 3 ; static int [ , ] dp = new int [ R , C ] ; static bool isvalid ( int i , int j ) { if ( i < 0 j < 0 i >= R j >= C ) return false ; return true ; } static bool isadjacent ( char prev , char curr ) { return ( ( curr - prev ) == 1 ) ; } static int getLenUtil ( char [ , ] mat , int i , int j , char prev ) { if ( ! isvalid ( i , j ) || ! isadjacent ( prev , mat [ i , j ] ) ) return 0 ; if ( dp [ i , j ] != - 1 ) return dp [ i , j ] ; int ans = 0 ; for ( int k = 0 ; k < 8 ; k ++ ) ans = Math . Max ( ans , 1 + getLenUtil ( mat , i + x [ k ] , j + y [ k ] , mat [ i , j ] ) ) ; return dp [ i , j ] = ans ; } static int getLen ( char [ , ] mat , char s ) { for ( int i = 0 ; i < R ; ++ i ) for ( int j = 0 ; j < C ; ++ j ) dp [ i , j ] = - 1 ; int ans = 0 ; for ( int i = 0 ; i < R ; i ++ ) { for ( int j = 0 ; j < C ; j ++ ) { if ( mat [ i , j ] == s ) { for ( int k = 0 ; k < 8 ; k ++ ) ans = Math . Max ( ans , 1 + getLenUtil ( mat , i + x [ k ] , j + y [ k ] , s ) ) ; } } } return ans ; } public static void Main ( ) { char [ , ] mat = { { ' a ' , ' c ' , ' d ' } , { ' h ' , ' b ' , ' a ' } , { ' i ' , ' g ' , ' f ' } } ; Console . WriteLine ( getLen ( mat , ' a ' ) ) ; Console . WriteLine ( getLen ( mat , ' e ' ) ) ; Console . WriteLine ( getLen ( mat , ' b ' ) ) ; Console . WriteLine ( getLen ( mat , ' f ' ) ) ; } }

Index/key variables: k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { public static int n = 3 ; public static int findLongestFromACell ( int i , int j , int [ ] [ ] mat , int [ ] [ ] dp ) { if ( i < 0 i >= n j < 0 j >= n ) { return 0 ; } if ( dp [ i ] [ j ] != - 1 ) { return dp [ i ] [ j ] ; } int x = int . MinValue , y = int . MinValue , z = int . MinValue , w = int . MinValue ; if ( j < n - 1 && ( ( mat [ i ] [ j ] + 1 ) == mat [ i ] [ j + 1 ] ) ) { x = dp [ i ] [ j ] = 1 + findLongestFromACell ( i , j + 1 , mat , dp ) ; } if ( j > 0 && ( mat [ i ] [ j ] + 1 == mat [ i ] [ j - 1 ] ) ) { y = dp [ i ] [ j ] = 1 + findLongestFromACell ( i , j - 1 , mat , dp ) ; } if ( i > 0 && ( mat [ i ] [ j ] + 1 == mat [ i - 1 ] [ j ] ) ) { z = dp [ i ] [ j ] = 1 + findLongestFromACell ( i - 1 , j , mat , dp ) ; } if ( i < n - 1 && ( mat [ i ] [ j ] + 1 == mat [ i + 1 ] [ j ] ) ) { w = dp [ i ] [ j ] = 1 + findLongestFromACell ( i + 1 , j , mat , dp ) ; } dp [ i ] [ j ] = Math . Max ( x , Math . Max ( y , Math . Max ( z , Math . Max ( w , 1 ) ) ) ) ; return dp [ i ] [ j ] ; } public static int finLongestOverAll ( int [ ] [ ] mat ) { int result = 1 ; int [ ] [ ] dp = RectangularArrays . ReturnRectangularIntArray ( n , n ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( dp [ i ] [ j ] == - 1 ) { findLongestFromACell ( i , j , mat , dp ) ; } result = Math . Max ( result , dp [ i ] [ j ] ) ; } } return result ; } public static class RectangularArrays { public static int [ ] [ ] ReturnRectangularIntArray ( int size1 , int size2 ) { int [ ] [ ] newArray = new int [ size1 ] [ ] ; for ( int array1 = 0 ; array1 < size1 ; array1 ++ ) { newArray [ array1 ] = new int [ size2 ] ; } return newArray ; } } public static void Main ( string [ ] args ) { int [ ] [ ] mat = new int [ ] [ ] { new int [ ] { 1 , 2 , 9 } , new int [ ] { 5 , 3 , 8 } , new int [ ] { 4 , 6 , 7 } } ; Console . WriteLine ( " Length ▁ of ▁ the ▁ longest ▁ path ▁ is ▁ " + finLongestOverAll ( mat ) ) ; } }

Index/key variables: array1, i, j, size1, size2
Accumulator variables: array1, i, j
Iterator variables: array1, i, j
Class/struct names: GFG, RectangularArrays
C# program:
using System ; class GFG { static int minInitialPoints ( int [ , ] points , int R , int C ) { int [ , ] dp = new int [ R , C ] ; int m = R , n = C ; dp [ m - 1 , n - 1 ] = points [ m - 1 , n - 1 ] > 0 ? 1 : Math . Abs ( points [ m - 1 , n - 1 ] ) + 1 ; for ( int i = m - 2 ; i >= 0 ; i -- ) dp [ i , n - 1 ] = Math . Max ( dp [ i + 1 , n - 1 ] - points [ i , n - 1 ] , 1 ) ; for ( int j = n - 2 ; j >= 0 ; j -- ) dp [ m - 1 , j ] = Math . Max ( dp [ m - 1 , j + 1 ] - points [ m - 1 , j ] , 1 ) ; for ( int i = m - 2 ; i >= 0 ; i -- ) { for ( int j = n - 2 ; j >= 0 ; j -- ) { int min_points_on_exit = Math . Min ( dp [ i + 1 , j ] , dp [ i , j + 1 ] ) ; dp [ i , j ] = Math . Max ( min_points_on_exit - points [ i , j ] , 1 ) ; } } return dp [ 0 , 0 ] ; } public static void Main ( ) { int [ , ] points = { { - 2 , - 3 , 3 } , { - 5 , - 10 , 1 } , { 10 , 30 , - 5 } } ; int R = 3 , C = 3 ; Console . Write ( " Minimum ▁ Initial ▁ Points ▁ Required : ▁ " + minInitialPoints ( points , R , C ) ) ; } }

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