dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int maxTripletSum ( int [ ] arr , int n ) { int sum = - 1000000 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) for ( int k = j + 1 ; k < n ; k ++ ) if ( sum < arr [ i ] + arr [ j ] + arr [ k ] ) sum = arr [ i ] + arr [ j ] + arr [ k ] ; return sum ; } public static void Main ( ) { int [ ] arr = { 1 , 0 , 8 , 6 , 4 , 2 } ; int n = arr . Length ; Console . WriteLine ( maxTripletSum ( arr , n ) ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxTripletSum ( int [ ] arr , int n ) { Array . Sort ( arr ) ; return arr [ n - 1 ] + arr [ n - 2 ] + arr [ n - 3 ] ; } public static void Main ( ) { int [ ] arr = { 1 , 0 , 8 , 6 , 4 , 2 } ; int n = arr . Length ; Console . WriteLine ( maxTripletSum ( arr , n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int maxTripletSum ( int [ ] arr , int n ) { int maxA = - 100000000 , maxB = - 100000000 ; int maxC = - 100000000 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > maxA ) { maxC = maxB ; maxB = maxA ; maxA = arr [ i ] ; } else if ( arr [ i ] > maxB ) { maxC = maxB ; maxB = arr [ i ] ; } else if ( arr [ i ] > maxC ) maxC = arr [ i ] ; } return ( maxA + maxB + maxC ) ; } public static void Main ( ) { int [ ] arr = { 1 , 0 , 8 , 6 , 4 , 2 } ; int n = arr . Length ; Console . WriteLine ( maxTripletSum ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static int search ( int [ ] arr , int x ) { int n = arr . Length ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == x ) return i ; } return - 1 ; } public static void Main ( ) { int [ ] arr = { 2 , 3 , 4 , 10 , 40 } ; int x = 10 ; int result = search ( arr , x ) ; if ( result == - 1 ) Console . WriteLine ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " ) ; else Console . WriteLine ( " Element ▁ is ▁ present ▁ at ▁ index ▁ " + result ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static void search ( int [ ] arr , int search_Element ) { int left = 0 ; int length = arr . Length ; int right = length - 1 ; int position = - 1 ; for ( left = 0 ; left <= right ; ) { if ( arr [ left ] == search_Element ) { position = left ; Console . WriteLine ( " Element ▁ found ▁ in ▁ Array ▁ at ▁ " + ( position + 1 ) + " ▁ Position ▁ with ▁ " + ( left + 1 ) + " ▁ Attempt " ) ; break ; } if ( arr [ right ] == search_Element ) { position = right ; Console . WriteLine ( " Element ▁ found ▁ in ▁ Array ▁ at ▁ " + ( position + 1 ) + " ▁ Position ▁ with ▁ " + ( length - right ) + " ▁ Attempt " ) ; break ; } left ++ ; right -- ; } if ( position == - 1 ) Console . WriteLine ( " Not ▁ found ▁ in ▁ Array ▁ with ▁ " + left + " ▁ Attempt " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int search_element = 5 ; search ( arr , search_element ) ; } }

Index/key variables: left, right
Accumulator variables: left, right
Iterator variables: left
Class/struct names: GFG
C# program:
using System ; class GFG { static void countsort ( char [ ] arr ) { int n = arr . Length ; char [ ] output = new char [ n ] ; int [ ] count = new int [ 256 ] ; for ( int i = 0 ; i < 256 ; ++ i ) count [ i ] = 0 ; for ( int i = 0 ; i < n ; ++ i ) ++ count [ arr [ i ] ] ; for ( int i = 1 ; i <= 255 ; ++ i ) count [ i ] += count [ i - 1 ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { output [ count [ arr [ i ] ] - 1 ] = arr [ i ] ; -- count [ arr [ i ] ] ; } for ( int i = 0 ; i < n ; ++ i ) arr [ i ] = output [ i ] ; } public static void Main ( ) { char [ ] arr = { ' g ' , ' e ' , ' e ' , ' k ' , ' s ' , ' f ' , ' o ' , ' r ' , ' g ' , ' e ' , ' e ' , ' k ' , ' s ' } ; countsort ( arr ) ; Console . Write ( " Sorted ▁ character ▁ array ▁ is ▁ " ) ; for ( int i = 0 ; i < arr . Length ; ++ i ) Console . Write ( arr [ i ] ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static void countSort ( int [ ] arr ) { int max = arr . Max ( ) ; int min = arr . Min ( ) ; int range = max - min + 1 ; int [ ] count = new int [ range ] ; int [ ] output = new int [ arr . Length ] ; for ( int i = 0 ; i < arr . Length ; i ++ ) { count [ arr [ i ] - min ] ++ ; } for ( int i = 1 ; i < count . Length ; i ++ ) { count [ i ] += count [ i - 1 ] ; } for ( int i = arr . Length - 1 ; i >= 0 ; i -- ) { output [ count [ arr [ i ] - min ] - 1 ] = arr [ i ] ; count [ arr [ i ] - min ] -- ; } for ( int i = 0 ; i < arr . Length ; i ++ ) { arr [ i ] = output [ i ] ; } } static void printArray ( int [ ] arr ) { for ( int i = 0 ; i < arr . Length ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } Console . WriteLine ( " " ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { - 5 , - 10 , 0 , - 3 , 8 , 5 , - 1 , 10 } ; countSort ( arr ) ; printArray ( arr ) ; } }

Index/key variables: i, range
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int binomialCoeff ( int n , int k ) { if ( k > n ) return 0 ; if ( k == 0 k == n ) return 1 ; return binomialCoeff ( n - 1 , k - 1 ) + binomialCoeff ( n - 1 , k ) ; } public static void Main ( ) { int n = 5 , k = 2 ; Console . Write ( " Value ▁ of ▁ C ( " + n + " , " + k + " ) ▁ is ▁ " + binomialCoeff ( n , k ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int binomialCoeff ( int n , int k ) { int [ ] C = new int [ k + 1 ] ; C [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . Min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } public static void Main ( ) { int n = 5 , k = 2 ; Console . WriteLine ( " Value ▁ of ▁ C ( " + n + " ▁ " + k + " ) ▁ is ▁ " + binomialCoeff ( n , k ) ) ; } }

Index/key variables: j, k
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; public class GFG { static int binomialCoeff ( int n , int r ) { if ( r > n ) return 0 ; long m = 1000000007 ; long [ ] inv = new long [ r + 1 ] ; inv [ 0 ] = 1 ; if ( r + 1 >= 2 ) inv [ 1 ] = 1 ; for ( int i = 2 ; i <= r ; i ++ ) { inv [ i ] = m - ( m / i ) * inv [ ( int ) ( m % i ) ] % m ; } int ans = 1 ; for ( int i = 2 ; i <= r ; i ++ ) { ans = ( int ) ( ( ( ans % m ) * ( inv [ i ] % m ) ) % m ) ; } for ( int i = n ; i >= ( n - r + 1 ) ; i -- ) { ans = ( int ) ( ( ( ans % m ) * ( i % m ) ) % m ) ; } return ans ; } public static void Main ( String [ ] args ) { int n = 5 , r = 2 ; Console . Write ( " Value ▁ of ▁ C ( " + n + " , ▁ " + r + " ) ▁ is ▁ " + binomialCoeff ( n , r ) + " STRNEWLINE " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static bool findPartiion ( int [ ] arr , int n ) { int sum = 0 ; int i , j ; for ( i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; if ( sum % 2 != 0 ) return false ; bool [ ] part = new bool [ sum / 2 + 1 ] ; for ( i = 0 ; i <= sum / 2 ; i ++ ) { part [ i ] = false ; } for ( i = 0 ; i < n ; i ++ ) { for ( j = sum / 2 ; j >= arr [ i ] ; j -- ) { if ( part [ j - arr [ i ] ] == true j == arr [ i ] ) part [ j ] = true ; } } return part [ sum / 2 ] ; } static void Main ( ) { int [ ] arr = { 1 , 3 , 3 , 2 , 3 , 2 } ; int n = 6 ; if ( findPartiion ( arr , n ) == true ) Console . WriteLine ( " Can ▁ be ▁ divided ▁ into ▁ two ▁ " + " subsets ▁ of ▁ equal ▁ sum " ) ; else Console . WriteLine ( " Can ▁ not ▁ be ▁ divided ▁ into ▁ " + " two ▁ subsets ▁ of ▁ equal ▁ sum " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int findoptimal ( int N ) { if ( N <= 6 ) return N ; int max = 0 ; int b ; for ( b = N - 3 ; b >= 1 ; b -- ) { int curr = ( N - b - 1 ) * findoptimal ( b ) ; if ( curr > max ) max = curr ; } return max ; } static void Main ( ) { int N ; for ( N = 1 ; N <= 20 ; N ++ ) Console . WriteLine ( " Maximum ▁ Number ▁ of ▁ A ' s ▁ with ▁ " + N + " ▁ keystrokes ▁ is ▁ " + findoptimal ( N ) ) ; } }

Accumulator variables: N, b
Iterator variables: N, b
Class/struct names: GFG
C# program:
using System ; public class GFG { static int findoptimal ( int N ) { if ( N <= 6 ) return N ; int [ ] screen = new int [ N ] ; int b ; int n ; for ( n = 1 ; n <= 6 ; n ++ ) screen [ n - 1 ] = n ; for ( n = 7 ; n <= N ; n ++ ) { screen [ n - 1 ] = 0 ; for ( b = n - 3 ; b >= 1 ; b -- ) { int curr = ( n - b - 1 ) * screen [ b - 1 ] ; if ( curr > screen [ n - 1 ] ) screen [ n - 1 ] = curr ; } } return screen [ N - 1 ] ; } public static void Main ( String [ ] args ) { int N ; for ( N = 1 ; N <= 20 ; N ++ ) Console . WriteLine ( " Maximum ▁ Number ▁ of ▁ A ' s ▁ with ▁ { 0 } ▁ keystrokes ▁ is ▁ { 1 } STRNEWLINE " , N , findoptimal ( N ) ) ; } }

Index/key variables: N
Accumulator variables: N, b, n
Iterator variables: N, b, n
Class/struct names: GFG
C# program:
using System ; class GFG { static int findoptimal ( int N ) { if ( N <= 6 ) return N ; int [ ] screen = new int [ N ] ; int n ; for ( n = 1 ; n <= 6 ; n ++ ) screen [ n - 1 ] = n ; for ( n = 7 ; n <= N ; n ++ ) { screen [ n - 1 ] = Math . Max ( 2 * screen [ n - 4 ] , Math . Max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ; } return screen [ N - 1 ] ; } public static void Main ( String [ ] args ) { int N ; for ( N = 1 ; N <= 20 ; N ++ ) Console . Write ( " Maximum ▁ Number ▁ of ▁ A ' s ▁ with " + " ▁ { 0 } ▁ keystrokes ▁ is ▁ { 1 } STRNEWLINE " , N , findoptimal ( N ) ) ; } }

Index/key variables: N
Accumulator variables: N, n
Iterator variables: N, n
Class/struct names: GFG
C# program:
using System ; public class GFG { static int power ( int x , int y ) { if ( y == 0 ) return 1 ; else if ( y % 2 == 0 ) return power ( x , y / 2 ) * power ( x , y / 2 ) ; else return x * power ( x , y / 2 ) * power ( x , y / 2 ) ; } public static void Main ( ) { int x = 2 ; int y = 3 ; Console . Write ( power ( x , y ) ) ; } }

Class/struct names: GFG
C# program:
using System ; public class GFG { static float power ( float x , int y ) { float temp ; if ( y == 0 ) return 1 ; temp = power ( x , y / 2 ) ; if ( y % 2 == 0 ) return temp * temp ; else { if ( y > 0 ) return x * temp * temp ; else return ( temp * temp ) / x ; } } public static void Main ( ) { float x = 2 ; int y = - 3 ; Console . Write ( power ( x , y ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { public static int power ( int x , int y ) { if ( y == 0 ) return 1 ; if ( x == 0 ) return 0 ; return x * power ( x , y - 1 ) ; } public static void Main ( String [ ] args ) { int x = 2 ; int y = 3 ; Console . WriteLine ( power ( x , y ) ) ; } }

Class/struct names: GFG
C# program:
using System ; public class GFG { public static int power ( int x , int y ) { return ( int ) Math . Pow ( x , y ) ; } static public void Main ( ) { int x = 2 ; int y = 3 ; Console . WriteLine ( power ( x , y ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static float squareRoot ( float n ) { float x = n ; float y = 1 ; double e = 0.000001 ; while ( x - y > e ) { x = ( x + y ) / 2 ; y = n / x ; } return x ; } public static void Main ( ) { int n = 50 ; Console . Write ( " Square ▁ root ▁ of ▁ " + n + " ▁ is ▁ " + squareRoot ( n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static float getAvg ( float prev_avg , float x , int n ) { return ( prev_avg * n + x ) / ( n + 1 ) ; } static void streamAvg ( float [ ] arr , int n ) { float avg = 0 ; for ( int i = 0 ; i < n ; i ++ ) { avg = getAvg ( avg , arr [ i ] , i ) ; Console . WriteLine ( " Average ▁ of ▁ { 0 } ▁ " + " numbers ▁ is ▁ { 1 } " , i + 1 , avg ) ; } return ; } public static void Main ( String [ ] args ) { float [ ] arr = { 10 , 20 , 30 , 40 , 50 , 60 } ; int n = arr . Length ; streamAvg ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int sum , n ; static float getAvg ( int x ) { sum += x ; return ( ( ( float ) sum ) / ++ n ) ; } static void streamAvg ( float [ ] arr , int n ) { float avg = 0 ; for ( int i = 0 ; i < n ; i ++ ) { avg = getAvg ( ( int ) arr [ i ] ) ; Console . WriteLine ( " Average ▁ of ▁ { 0 } ▁ numbers ▁ " + " is ▁ { 1 } " , ( i + 1 ) , avg ) ; } return ; } static int Main ( ) { float [ ] arr = new float [ ] { 10 , 20 , 30 , 40 , 50 , 60 } ; int n = arr . Length ; streamAvg ( arr , n ) ; return 0 ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class BinomialCoefficient { static int binomialCoeff ( int n , int k ) { int res = 1 ; if ( k > n - k ) k = n - k ; for ( int i = 0 ; i < k ; ++ i ) { res *= ( n - i ) ; res /= ( i + 1 ) ; } return res ; } public static void Main ( ) { int n = 8 ; int k = 2 ; Console . Write ( " Value ▁ of ▁ C ( " + n + " , ▁ " + k + " ) ▁ " + " is " + " ▁ " + binomialCoeff ( n , k ) ) ; } }

Accumulator variables: res
Iterator variables: i
Class/struct names: BinomialCoefficient
C# program:
using System ; class GFG { static void printCombination ( int [ ] arr , int n , int r ) { int [ ] data = new int [ r ] ; combinationUtil ( arr , data , 0 , n - 1 , 0 , r ) ; } static void combinationUtil ( int [ ] arr , int [ ] data , int start , int end , int index , int r ) { if ( index == r ) { for ( int j = 0 ; j < r ; j ++ ) Console . Write ( data [ j ] + " ▁ " ) ; Console . WriteLine ( " " ) ; return ; } for ( int i = start ; i <= end && end - i + 1 >= r - index ; i ++ ) { data [ index ] = arr [ i ] ; combinationUtil ( arr , data , i + 1 , end , index + 1 , r ) ; } } static public void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int r = 3 ; int n = arr . Length ; printCombination ( arr , n , r ) ; } }

Index/key variables: i, index, j, r
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void printCombination ( int [ ] arr , int n , int r ) { int [ ] data = new int [ r ] ; combinationUtil ( arr , n , r , 0 , data , 0 ) ; } static void combinationUtil ( int [ ] arr , int n , int r , int index , int [ ] data , int i ) { if ( index == r ) { for ( int j = 0 ; j < r ; j ++ ) Console . Write ( data [ j ] + " ▁ " ) ; Console . WriteLine ( " " ) ; return ; } if ( i >= n ) return ; data [ index ] = arr [ i ] ; combinationUtil ( arr , n , r , index + 1 , data , i + 1 ) ; combinationUtil ( arr , n , r , index , data , i + 1 ) ; } static public void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int r = 3 ; int n = arr . Length ; printCombination ( arr , n , r ) ; } }

Index/key variables: i, index, j, r
Accumulator variables: j
Iterator variables: j
Class/struct names: GFG
C# program:
using System ; class FindGroups { int findgroups ( int [ ] arr , int n ) { int [ ] c = new int [ ] { 0 , 0 , 0 } ; int i ; int res = 0 ; for ( i = 0 ; i < n ; i ++ ) c [ arr [ i ] % 3 ] ++ ; res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 ) ; res += c [ 1 ] * c [ 2 ] ; res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6 ; res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6 ; res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 ) ; res += c [ 0 ] * c [ 1 ] * c [ 2 ] ; return res ; } public static void Main ( ) { FindGroups groups = new FindGroups ( ) ; int [ ] arr = { 3 , 6 , 7 , 2 , 9 } ; int n = arr . Length ; Console . Write ( " Required ▁ number ▁ of ▁ groups ▁ are ▁ " + groups . findgroups ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, res
Iterator variables: i
Class/struct names: FindGroups
C# program:
using System ; class GFG { static int nextPowerOf2 ( int n ) { int p = 1 ; if ( n > 0 && ( n & ( n - 1 ) ) == 0 ) return n ; while ( p < n ) p <<= 1 ; return p ; } public static void Main ( ) { int n = 5 ; Console . Write ( nextPowerOf2 ( n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static int nextPowerOf2 ( int n ) { n -- ; n |= n >> 1 ; n |= n >> 2 ; n |= n >> 4 ; n |= n >> 8 ; n |= n >> 16 ; n ++ ; return n ; } public static void Main ( ) { int n = 5 ; Console . WriteLine ( nextPowerOf2 ( n ) ) ; } }

Accumulator variables: n
Class/struct names: GFG
C# program:
using System ; class GFG { static void segregate0and1 ( int [ ] arr , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) count ++ ; } for ( int i = 0 ; i < count ; i ++ ) arr [ i ] = 0 ; for ( int i = count ; i < n ; i ++ ) arr [ i ] = 1 ; } static void print ( int [ ] arr , int n ) { Console . WriteLine ( " Array ▁ after ▁ segregation ▁ is ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } public static void Main ( ) { int [ ] arr = new int [ ] { 0 , 1 , 0 , 1 , 1 , 1 } ; int n = arr . Length ; segregate0and1 ( arr , n ) ; print ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class Segregate { void segregate0and1 ( int [ ] arr , int size ) { int left = 0 , right = size - 1 ; while ( left < right ) { while ( arr [ left ] == 0 && left < right ) left ++ ; while ( arr [ right ] == 1 && left < right ) right -- ; if ( left < right ) { arr [ left ] = 0 ; arr [ right ] = 1 ; left ++ ; right -- ; } } } public static void Main ( ) { Segregate seg = new Segregate ( ) ; int [ ] arr = new int [ ] { 0 , 1 , 0 , 1 , 1 , 1 } ; int i , arr_size = arr . Length ; seg . segregate0and1 ( arr , arr_size ) ; Console . WriteLine ( " Array ▁ after ▁ segregation ▁ is ▁ " ) ; for ( i = 0 ; i < 6 ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } }

Index/key variables: i, left, right
Accumulator variables: i, left, right
Iterator variables: i
Class/struct names: Segregate
C# program:
using System ; class GFG { static void segregate0and1 ( int [ ] arr ) { int type0 = 0 ; int type1 = arr . Length - 1 ; while ( type0 < type1 ) { if ( arr [ type0 ] == 1 ) { arr [ type1 ] = arr [ type1 ] + arr [ type0 ] ; arr [ type0 ] = arr [ type1 ] - arr [ type0 ] ; arr [ type1 ] = arr [ type1 ] - arr [ type0 ] ; type1 -- ; } else { type0 ++ ; } } } public static void Main ( string [ ] args ) { int [ ] array = new int [ ] { 0 , 1 , 0 , 1 , 1 , 1 } ; segregate0and1 ( array ) ; Console . Write ( " Array ▁ after ▁ segregation ▁ is ▁ " ) ; foreach ( int a in array ) { Console . Write ( a + " ▁ " ) ; } } }

Index/key variables: type0, type1
Accumulator variables: type0, type1
Iterator variables: a
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { public static void distinctAdjacentElement ( int [ ] a , int n ) { Dictionary < int , int > m = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( m . ContainsKey ( a [ i ] ) ) { int x = m [ a [ i ] ] + 1 ; m [ a [ i ] ] = x ; } else { m [ a [ i ] ] = 1 ; } } int mx = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( mx < m [ a [ i ] ] ) { mx = m [ a [ i ] ] ; } } if ( mx > ( n + 1 ) / 2 ) { Console . WriteLine ( " NO " ) ; } else { Console . WriteLine ( " YES " ) ; } } public static void Main ( string [ ] args ) { int [ ] a = new int [ ] { 7 , 7 , 7 , 7 } ; int n = 4 ; distinctAdjacentElement ( a , n ) ; } }

Index/key variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int maxIndexDiff ( int [ ] arr , int n ) { int maxDiff = - 1 ; int i , j ; for ( i = 0 ; i < n ; ++ i ) { for ( j = n - 1 ; j > i ; -- j ) { if ( arr [ j ] > arr [ i ] && maxDiff < ( j - i ) ) maxDiff = j - i ; } } return maxDiff ; } public static void Main ( ) { int [ ] arr = { 9 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 18 , 0 } ; int n = arr . Length ; int maxDiff = maxIndexDiff ( arr , n ) ; Console . Write ( maxDiff ) ; } }

Index/key variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { public static void Main ( String [ ] args ) { int [ ] v = { 34 , 8 , 10 , 3 , 2 , 80 , 30 , 33 , 1 } ; int n = v . Length ; int [ ] maxFromEnd = new int [ n + 1 ] ; for ( int i = 0 ; i < maxFromEnd . Length ; i ++ ) maxFromEnd [ i ] = int . MinValue ; for ( int i = v . Length - 1 ; i >= 0 ; i -- ) { maxFromEnd [ i ] = Math . Max ( maxFromEnd [ i + 1 ] , v [ i ] ) ; } int result = 0 ; for ( int i = 0 ; i < v . Length ; i ++ ) { int low = i + 1 , high = v . Length - 1 , ans = i ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( v [ i ] <= maxFromEnd [ mid ] ) { ans = Math . Max ( ans , mid ) ; low = mid + 1 ; } else { high = mid - 1 ; } } result = Math . Max ( result , ans - i ) ; } Console . Write ( result + " STRNEWLINE " ) ; } }

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static int maxIndexDiff ( List < int > arr , int n ) { Dictionary < int , List < int > > hashmap = new Dictionary < int , List < int > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( hashmap . ContainsKey ( arr [ i ] ) ) { hashmap [ arr [ i ] ] . Add ( i ) ; } else { hashmap . Add ( arr [ i ] , new List < int > ( ) ) ; hashmap [ arr [ i ] ] . Add ( i ) ; } } arr . Sort ( ) ; int maxDiff = - 1 ; int temp = n ; for ( int i = 0 ; i < n ; i ++ ) { if ( temp > hashmap [ arr [ i ] ] [ 0 ] ) { temp = hashmap [ arr [ i ] ] [ 0 ] ; } maxDiff = Math . Max ( maxDiff , hashmap [ arr [ i ] ] [ hashmap [ arr [ i ] ] . Count - 1 ] - temp ) ; } return maxDiff ; } static public void Main ( ) { int n = 9 ; List < int > arr = new List < int > ( ) ; arr . Add ( 34 ) ; arr . Add ( 8 ) ; arr . Add ( 10 ) ; arr . Add ( 3 ) ; arr . Add ( 2 ) ; arr . Add ( 80 ) ; arr . Add ( 30 ) ; arr . Add ( 33 ) ; arr . Add ( 1 ) ; int ans = maxIndexDiff ( arr , n ) ; Console . WriteLine ( " The ▁ maxIndexDiff ▁ is ▁ : ▁ " + ans ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static void printRepeating ( int [ ] arr , int size ) { SortedSet < int > s = new SortedSet < int > ( arr ) ; foreach ( var n in s ) { Console . Write ( n + " ▁ " ) ; } } public static void Main ( ) { int [ ] arr = { 1 , 3 , 2 , 2 , 1 } ; int n = arr . Length ; printRepeating ( arr , n ) ; } }

Iterator variables: n
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; using System . Linq ; public class GFG { static int minSwapsToSort ( int [ ] arr , int n ) { List < List < int > > arrPos = new List < List < int > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { arrPos . Add ( new List < int > ( ) { arr [ i ] , i } ) ; } arrPos = arrPos . OrderBy ( x => x [ 0 ] ) . ToList ( ) ; bool [ ] vis = new bool [ n ] ; Array . Fill ( vis , false ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( vis [ i ] arrPos [ i ] [ 1 ] == i ) continue ; int cycle_size = 0 ; int j = i ; while ( ! vis [ j ] ) { vis [ j ] = true ; j = arrPos [ j ] [ 1 ] ; cycle_size ++ ; } ans += ( cycle_size - 1 ) ; } return ans ; } static int minSwapToMakeArraySame ( int [ ] a , int [ ] b , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mp . Add ( b [ i ] , i ) ; } for ( int i = 0 ; i < n ; i ++ ) { b [ i ] = mp [ a [ i ] ] ; } return minSwapsToSort ( b , n ) ; } static public void Main ( ) { int [ ] a = { 3 , 6 , 4 , 8 } ; int [ ] b = { 4 , 6 , 8 , 3 } ; int n = a . Length ; Console . WriteLine ( minSwapToMakeArraySame ( a , b , n ) ) ; } }

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