dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int ctr = 0 ; static int find ( int [ ] parent , int x ) { if ( parent [ x ] == x ) return x ; parent [ x ] = find ( parent , parent [ x ] ) ; return parent [ x ] ; } static void setUnion ( int [ ] parent , int [ ] rank , int x , int y ) { int parentx = find ( parent , x ) ; int parenty = find ( parent , y ) ; if ( parenty == parentx ) return ; ctr -- ; if ( rank [ parentx ] < rank [ parenty ] ) { parent [ parentx ] = parenty ; } else if ( rank [ parentx ] > rank [ parenty ] ) { parent [ parenty ] = parentx ; } else { parent [ parentx ] = parenty ; rank [ parenty ] ++ ; } } static int [ ] solve ( int n , int m , int [ , ] query ) { int [ ] result = new int [ query . Length ] ; int [ ] parent = new int [ n * m ] ; for ( int i = 0 ; i < n * m ; i ++ ) parent [ i ] = i ; int [ ] rank = new int [ n * m ] ; for ( int i = 0 ; i < rank . Length ; i ++ ) rank [ i ] = 1 ; bool [ ] grid = new bool [ n * m ] ; for ( int i = 0 ; i < query . GetLength ( 0 ) ; i ++ ) { int x = query [ i , 0 ] ; int y = query [ i , 1 ] ; if ( grid [ m * x + y ] == true ) { result [ i ] = ctr ; continue ; } grid [ m * x + y ] = true ; ctr ++ ; if ( x > 0 && grid [ m * ( x - 1 ) + y ] == true ) setUnion ( parent , rank , m * x + y , m * ( x - 1 ) + y ) ; if ( y > 0 && grid [ m * ( x ) + y - 1 ] == true ) setUnion ( parent , rank , m * x + y , m * ( x ) + y - 1 ) ; if ( x < n - 1 && grid [ m * ( x + 1 ) + y ] == true ) setUnion ( parent , rank , m * x + y , m * ( x + 1 ) + y ) ; if ( y < m - 1 && grid [ m * ( x ) + y + 1 ] == true ) setUnion ( parent , rank , m * x + y , m * ( x ) + y + 1 ) ; result [ i ] = ctr ; } return result ; } public static void Main ( String [ ] args ) { int N = 3 , M = 3 , K = 4 ; int [ , ] query = { { 0 , 0 } , { 1 , 1 } , { 1 , 0 } , { 1 , 2 } } ; int [ ] result = solve ( N , M , query ) ; for ( int i = 0 ; i < K ; i ++ ) Console . Write ( result [ i ] + " ▁ " ) ; } }

Index/key variables: i, parentx, parenty, x
Accumulator variables: ctr, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static void findMinSum ( int [ ] A , int K ) { int n = A . Length ; int [ ] suffix_min = new int [ n ] ; suffix_min [ n - 1 ] = A [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) suffix_min [ i ] = Math . Min ( suffix_min [ i + 1 ] , A [ i ] ) ; int min_sum = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( i + K < n ) min_sum = Math . Min ( min_sum , A [ i ] + suffix_min [ i + K ] ) ; } Console . WriteLine ( min_sum ) ; } public static void Main ( String [ ] args ) { int [ ] A = { 1 , 2 , 3 , 4 , 5 , 6 } ; int K = 2 ; findMinSum ( A , K ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static long FindMaxDif ( List < long > a , int m ) { int n = m / 3 ; long [ ] l = new long [ m + 5 ] ; long [ ] r = new long [ m + 5 ] ; List < long > s = new List < long > ( ) ; for ( int i = 1 ; i <= m ; i ++ ) { if ( i <= n ) { l [ i ] = a [ i - 1 ] + l [ i - 1 ] ; s . Add ( a [ i - 1 ] ) ; } else { l [ i ] = l [ i - 1 ] ; s . Sort ( ) ; long d = s [ 0 ] ; if ( a [ i - 1 ] > d ) { l [ i ] -= d ; l [ i ] += a [ i - 1 ] ; s . Remove ( d ) ; s . Add ( a [ i - 1 ] ) ; } } } s . Clear ( ) ; for ( int i = m ; i >= 1 ; i -- ) { if ( i >= m - n + 1 ) { r [ i ] = a [ i - 1 ] + r [ i + 1 ] ; s . Add ( a [ i - 1 ] ) ; } else { r [ i ] = r [ i + 1 ] ; s . Sort ( ) ; long d = s [ s . Count - 1 ] ; if ( a [ i - 1 ] < d ) { r [ i ] -= d ; r [ i ] += a [ i - 1 ] ; s . Remove ( d ) ; s . Add ( a [ i - 1 ] ) ; } } } long ans = ( long ) ( - 9e18 ) ; for ( int i = n ; i <= m - n ; i ++ ) { ans = Math . Max ( ans , l [ i ] - r [ i + 1 ] ) ; } return ans ; } static void Main ( ) { List < long > vtr = new List < long > ( new long [ ] { 3 , 1 , 4 , 1 , 5 , 9 } ) ; int n = vtr . Count ; Console . Write ( FindMaxDif ( vtr , 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 String checkPossible ( int [ ] A , int [ ] B , int n ) { HashSet values = new HashSet ( ) ; for ( int i = 0 ; i < n ; i ++ ) { values . Add ( B [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( values . Contains ( A [ i ] + A [ j ] ) ) { values . Remove ( A [ i ] + A [ j ] ) ; if ( values . Count == 0 ) break ; } } } if ( values . Count == 0 ) return " Yes " ; else return " No " ; } public static void Main ( String [ ] args ) { int N = 5 ; int [ ] A = { 3 , 5 , 1 , 4 , 2 } ; int [ ] B = { 3 , 4 , 5 , 6 , 7 } ; Console . Write ( checkPossible ( A , B , N ) ) ; } }

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 N = ( int ) 2e5 ; static int V = 500 ; static void solve ( int n , int d , int [ ] input ) { int [ ] a = new int [ N ] ; int [ ] cnt = new int [ V + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) a [ i ] = input [ i ] ; int answer = 0 ; for ( int i = 0 ; i < d ; ++ i ) cnt [ a [ i ] ] ++ ; for ( int i = d ; i <= n - 1 ; ++ i ) { int acc = 0 ; int low_median = - 1 , high_median = - 1 ; for ( int v = 0 ; v <= V ; ++ v ) { acc += cnt [ v ] ; if ( low_median == - 1 && acc >= ( int ) ( Math . Floor ( ( d + 1 ) / 2.0 ) ) ) low_median = v ; if ( high_median == - 1 && acc >= ( int ) ( Math . Ceiling ( ( d + 1 ) / 2.0 ) ) ) high_median = v ; } int double_median = low_median + high_median ; if ( a [ i ] >= double_median ) answer ++ ; cnt [ a [ i - d ] ] -- ; cnt [ a [ i ] ] ++ ; } Console . Write ( answer + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] input = { 1 , 2 , 2 , 4 , 5 } ; int n = input . Length ; int k = 3 ; solve ( n , k , input ) ; } }

Index/key variables: N, i, v
Accumulator variables: acc, answer
Iterator variables: i, v
Class/struct names: GFG
C# program:
using System ; class GFG { static int findMinSoln ( int n , int k ) { int minSoln = int . MaxValue ; for ( int i = 1 ; i < k ; i ++ ) { if ( n % i == 0 ) minSoln = Math . Min ( minSoln , ( n / i ) * k + i ) ; } return minSoln ; } public static void Main ( String [ ] args ) { int n = 4 , k = 6 ; Console . WriteLine ( findMinSoln ( n , k ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int getSum ( int [ ] BITree , int index ) { int ans = 0 ; index += 1 ; while ( index > 0 ) { ans += BITree [ index ] ; index -= index & ( - index ) ; } return ans ; } static void updateBIT ( int [ ] BITree , int n , int index , int val ) { index = index + 1 ; while ( index <= n ) { BITree [ index ] += val ; index += index & ( - index ) ; } } static int [ ] constructBITree ( int [ ] arr , int n ) { int [ ] BITree = new int [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) BITree [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) updateBIT ( BITree , n , i , arr [ i ] ) ; return BITree ; } static int getLowerBound ( int [ ] BITree , int [ ] arr , int n , int k ) { int lb = - 1 ; int l = 0 , r = n - 1 ; while ( l <= r ) { int mid = l + ( r - l ) / 2 ; if ( getSum ( BITree , mid ) >= k ) { r = mid - 1 ; lb = mid ; } else l = mid + 1 ; } return lb ; } static void performQueries ( int [ ] A , int n , int [ , ] q ) { int [ ] BITree = constructBITree ( A , n ) ; for ( int i = 0 ; i < q . GetLength ( 0 ) ; i ++ ) { int id = q [ i , 0 ] ; if ( id == 1 ) { int idx = q [ i , 1 ] ; int val = q [ i , 2 ] ; A [ idx ] += val ; updateBIT ( BITree , n , idx , val ) ; } else { int k = q [ i , 1 ] ; int lb = getLowerBound ( BITree , A , n , k ) ; Console . WriteLine ( lb ) ; } } } public static void Main ( String [ ] args ) { int [ ] A = { 1 , 2 , 3 , 5 , 8 } ; int n = A . Length ; int [ , ] q = { { 1 , 0 , 2 } , { 2 , 5 , 0 } , { 1 , 3 , 5 } } ; performQueries ( A , n , q ) ; } }

Index/key variables: i, idx, index
Accumulator variables: ans, i, index
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int cnt = 0 ; static void dfs ( int [ ] val , int [ ] cost , List < int > [ ] tr , int u , int s ) { s = s + cost [ u ] ; if ( s < 0 ) s = 0 ; if ( s > val [ u ] ) return ; cnt ++ ; for ( int i = 0 ; i < tr [ u ] . Count ; i ++ ) { dfs ( val , cost , tr , tr [ u ] [ i ] , s ) ; } } public static void Main ( String [ ] args ) { int n = 9 ; int [ ] val = { 88 , 22 , 83 , 14 , 95 , 91 , 98 , 53 , 11 } ; int [ ] cost = { - 1 , 24 , - 8 , 67 , 64 , 65 , 12 , - 80 , 8 } ; List < int > [ ] tr = new List < int > [ n + 1 ] ; for ( int i = 0 ; i < tr . Length ; i ++ ) tr [ i ] = new List < int > ( ) ; tr [ 0 ] . Add ( 3 ) ; tr [ 0 ] . Add ( 4 ) ; tr [ 4 ] . Add ( 6 ) ; tr [ 6 ] . Add ( 2 ) ; tr [ 2 ] . Add ( 1 ) ; tr [ 2 ] . Add ( 8 ) ; tr [ 8 ] . Add ( 5 ) ; tr [ 5 ] . Add ( 7 ) ; dfs ( val , cost , tr , 0 , 0 ) ; Console . Write ( n - cnt ) ; } }

Index/key variables: i, u
Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static Boolean ContinuousElements ( int [ ] a , int n ) { if ( n == 1 ) return false ; int curr = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] != a [ i - 1 ] ) { if ( curr == 1 ) return false ; else curr = 0 ; } curr ++ ; } if ( curr == 1 ) return false ; return true ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 1 , 2 , 2 , 1 , 3 , 3 } ; int n = a . Length ; if ( ContinuousElements ( a , n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }

Index/key variables: i
Accumulator variables: curr, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static int BFS ( int [ , ] mat , int row , int col ) { int area = 0 ; Queue < pair > Q = new Queue < pair > ( ) ; Q . Enqueue ( new pair ( row , col ) ) ; while ( Q . Count != 0 ) { pair it = Q . Peek ( ) ; Q . Dequeue ( ) ; int r = it . first , c = it . second ; if ( r < 0 c < 0 r > 4 c > 4 ) continue ; if ( mat [ r , c ] == 0 ) continue ; if ( mat [ r , c ] == 1 ) { mat [ r , c ] = 0 ; area ++ ; } Q . Enqueue ( new pair ( r + 1 , c ) ) ; Q . Enqueue ( new pair ( r - 1 , c ) ) ; Q . Enqueue ( new pair ( r , c + 1 ) ) ; Q . Enqueue ( new pair ( r , c - 1 ) ) ; } return area ; } static void sizeOfConnections ( int [ , ] mat ) { ArrayList result = new ArrayList ( ) ; for ( int row = 0 ; row < 5 ; ++ row ) { for ( int col = 0 ; col < 5 ; ++ col ) { if ( mat [ row , col ] == 1 ) { int area = BFS ( mat , row , col ) ; result . Add ( area ) ; } } } foreach ( int val in result ) Console . Write ( val + " ▁ " ) ; } public static void Main ( string [ ] args ) { int [ , ] mat = { { 1 , 1 , 0 , 0 , 0 } , { 1 , 1 , 0 , 1 , 1 } , { 1 , 0 , 0 , 1 , 1 } , { 1 , 0 , 0 , 0 , 0 } , { 0 , 0 , 1 , 1 , 1 } } ; sizeOfConnections ( mat ) ; } }

Accumulator variables: area
Iterator variables: col, row, val
Class/struct names: GFG, pair
C# program:
using System ; class GFG { static void maxProduct ( int [ ] arr , int N ) { if ( N < 3 ) { return ; } Array . Sort ( arr ) ; int smallest1 = arr [ 0 ] ; int smallest3 = arr [ 2 ] ; int largest1 = arr [ N - 1 ] ; int largest3 = arr [ N - 3 ] ; if ( smallest1 * smallest3 >= largest1 * largest3 ) { Console . Write ( smallest1 + " ▁ " + smallest3 ) ; } else { Console . Write ( largest1 + " ▁ " + largest3 ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 2 , 67 , 45 , 160 , 78 } ; int N = arr . Length ; maxProduct ( arr , N ) ; } }

Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int maxLen ( int [ ] A , int N ) { List < List < int > > v = new List < List < int > > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] == 1 ) { int s = i , len ; while ( i < N && A [ i ] == 1 ) { i ++ ; } len = i - s ; List < int > l = new List < int > { len , s , i - 1 } ; v . Add ( l ) ; } } if ( v . Count == 0 ) { return - 1 ; } int ans = 0 ; for ( int i = 0 ; i < v . Count - 1 ; i ++ ) { ans = Math . Max ( ans , v [ i ] [ 0 ] ) ; if ( v [ i + 1 ] [ 1 ] - v [ i ] [ 2 ] - 1 == 2 ) { ans = Math . Max ( ans , v [ i ] [ 0 ] + v [ i + 1 ] [ 0 ] ) ; } if ( v [ i + 1 ] [ 1 ] - v [ i ] [ 2 ] - 1 == 1 ) { ans = Math . Max ( ans , v [ i ] [ 0 ] + v [ i + 1 ] [ 0 ] - 1 ) ; } } ans = Math . Max ( v [ v . Count - 1 ] [ 0 ] , ans ) ; return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 0 , 1 , 0 , 0 , 1 } ; int N = arr . Length ; Console . WriteLine ( maxLen ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static int n ; static Stack < int > s ; static ArrayList tsort ; static ArrayList adj ; static int [ ] visited = new int [ 100001 ] ; static void dfs ( int u ) { visited [ u ] = 1 ; foreach ( int it in ( ArrayList ) adj [ u ] ) { if ( visited [ it ] == 0 ) dfs ( it ) ; } s . Push ( u ) ; } static bool check_cycle ( ) { Dictionary < int , int > pos = new Dictionary < int , int > ( ) ; int ind = 0 ; while ( s . Count != 0 ) { pos . Add ( s . Peek ( ) , ind ) ; tsort . Add ( s . Peek ( ) ) ; ind += 1 ; s . Pop ( ) ; } for ( int i = 0 ; i < n ; i ++ ) { foreach ( int it in ( ArrayList ) adj [ i ] ) { if ( pos [ i ] > pos [ it ] ) { return true ; } } } return false ; } static void addEdge ( int u , int v ) { ( ( ArrayList ) adj [ u ] ) . Add ( v ) ; } public static void Main ( string [ ] args ) { n = 4 ; s = new Stack < int > ( ) ; adj = new ArrayList ( ) ; tsort = new ArrayList ( ) ; for ( int i = 0 ; i < 4 ; i ++ ) adj . Add ( new ArrayList ( ) ) ; addEdge ( 0 , 1 ) ; addEdge ( 0 , 2 ) ; addEdge ( 1 , 2 ) ; addEdge ( 2 , 0 ) ; addEdge ( 2 , 3 ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( visited [ i ] == 0 ) { dfs ( i ) ; } } if ( check_cycle ( ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }

Index/key variables: i, it, u
Accumulator variables: i, ind
Iterator variables: i, it
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void printNewArray ( List < int > a , int n ) { List < Tuple < int , int > > v = new List < Tuple < int , int > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { v . Add ( new Tuple < int , int > ( a [ i ] , i ) ) ; } v . Sort ( ) ; int [ ] ans = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ v [ ( i + 1 ) % n ] . Item2 ] = v [ i ] . Item1 ; } for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( ans [ i ] + " ▁ " ) ; } } static void Main ( ) { List < int > a = new List < int > ( new int [ ] { 4 , 1 , 2 , 5 , 3 } ) ; int n = a . Count ; printNewArray ( a , n ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int min_remove ( int [ ] arr , int n , int k ) { Array . Sort ( arr ) ; int ans = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { if ( arr [ j ] - arr [ i ] <= k ) { ans = Math . Min ( ans , n - j + i - 1 ) ; } } } return ans ; } public static void Main ( String [ ] args ) { int k = 3 ; int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . Length ; Console . Write ( min_remove ( arr , n , k ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static void solve ( int [ ] arr , int n ) { int countzeroes = 0 ; int countones = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == 0 ) countzeroes ++ ; else countones ++ ; } if ( Math . Abs ( countzeroes - countones ) == 1 ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 0 , 1 , 0 , 0 , 1 , 1 , 1 } ; int n = arr . Length ; solve ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: countones, countzeroes, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static char bs ( char [ ] ar , int n , int ele ) { int start = 0 ; int end = n - 1 ; char ch = ' @ ' ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; if ( ar [ mid ] == ele ) end = mid - 1 ; else if ( ar [ mid ] < ele ) { ch = ar [ mid ] ; start = mid + 1 ; } else end = mid - 1 ; } return ch ; } public static void Main ( String [ ] args ) { char [ ] ar = { ' e ' , ' g ' , ' t ' , ' y ' } ; int n = ar . Length ; char K = ' u ' ; char ch = bs ( ar , n , K ) ; if ( ch == ' @ ' ) Console . Write ( " - 1" ) ; else Console . Write ( ch ) ; } }

Index/key variables: mid
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int findMaxLen ( int [ ] a , int k ) { int n = a . Length ; Array . Sort ( a ) ; bool [ ] vis = new bool [ n ] ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mp . Add ( a [ i ] , i ) ; } int c = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( vis [ i ] == false ) { int check = a [ i ] * k ; if ( mp . ContainsKey ( check ) ) { c ++ ; vis [ mp [ check ] ] = true ; } } } return n - c ; } public static void Main ( String [ ] args ) { int K = 3 ; int [ ] arr = { 1 , 4 , 3 , 2 } ; Console . Write ( findMaxLen ( arr , K ) ) ; } }

Index/key variables: check, i, n
Accumulator variables: c, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System . Collections . Generic ; using System ; class GFG { static int getPrefixLength ( string srcStr , string targetStr ) { if ( targetStr . Length == 0 ) return 0 ; srcStr = srcStr . ToLower ( ) ; targetStr = targetStr . ToLower ( ) ; Dictionary < char , int > dictCount = new Dictionary < char , int > ( ) ; int nUnique = 0 ; foreach ( var ch in targetStr ) { if ( dictCount . ContainsKey ( ch ) != true ) { nUnique += 1 ; dictCount [ ch ] = 0 ; } dictCount [ ch ] += 1 ; } for ( int i = 0 ; i < srcStr . Length ; i ++ ) { char ch = srcStr [ i ] ; if ( dictCount . ContainsKey ( ch ) != true ) continue ; dictCount [ ch ] -= 1 ; if ( dictCount [ ch ] == 0 ) nUnique -= 1 ; if ( nUnique == 0 ) return ( i + 1 ) ; } return - 1 ; } public static void Main ( ) { string S = " MarvoloGaunt " ; string T = " Tom " ; Console . Write ( getPrefixLength ( S , T ) ) ; } }

Index/key variables: ch, i
Accumulator variables: i, nUnique
Iterator variables: ch, i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static bool check ( char [ ] str , int mid , char a ) { int n = str . Length ; int previous = - 1 , i ; for ( i = 0 ; i < n ; ++ i ) { if ( str [ i ] == a ) { if ( i - previous > mid ) { return false ; } previous = i ; } } if ( i - previous > mid ) return false ; else return true ; } static bool possible ( char [ ] str , int mid ) { for ( int i = 0 ; i < 26 ; ++ i ) { if ( check ( str , mid , ( char ) ( i + ' a ' ) ) ) return true ; } return false ; } static int findMinLength ( char [ ] str ) { int low = 1 , high = str . Length ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( possible ( str , mid ) ) high = mid - 1 ; else low = mid + 1 ; } return high + 1 ; } static bool ifAllDistinct ( String str ) { HashSet < char > s = new HashSet < char > ( ) ; foreach ( char c in str . ToCharArray ( ) ) { s . Add ( c ) ; } return s . Count == str . Length ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; if ( ifAllDistinct ( str ) ) Console . Write ( - 1 + " STRNEWLINE " ) ; else Console . Write ( findMinLength ( str . ToCharArray ( ) ) ) ; } }

Index/key variables: i
Iterator variables: c, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int solve ( int [ ] A , int N ) { int i = 0 ; int k = 0 ; for ( int j = 1 ; j < N ; j ++ ) { int tempK = Math . Min ( A [ i ] , A [ j ] ) / ( j - i ) ; if ( tempK > k ) { k = tempK ; } if ( A [ j ] >= A [ i ] / ( j - i ) ) i = j ; } return k ; } public static void Main ( string [ ] args ) { int [ ] A = { 10 , 5 , 12 , 15 , 8 } ; int N = A . Length ; Console . Write ( solve ( A , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: j
Iterator variables: j
Class/struct names: GFG
C# program:
using System ; class GFG { static void split ( int [ ] arr , int n ) { Array . Sort ( arr ) ; int count = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] == 1 ) { count = 2 ; break ; } } Console . Write ( count ) ; } public static void Main ( string [ ] args ) { int [ ] arr = new int [ ] { 2 , 4 , 6 } ; int n = arr . Length ; split ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static bool check ( String str1 , String str2 ) { bool [ ] mark = new bool [ 26 ] ; int n = str1 . Length , m = str2 . Length ; for ( int i = 0 ; i < n ; i ++ ) { mark [ str1 [ i ] - ' a ' ] = true ; } for ( int i = 0 ; i < m ; i ++ ) { if ( mark [ str2 [ i ] - ' a ' ] ) return true ; } return false ; } public static void Main ( String [ ] args ) { String str1 = " abca " , str2 = " efad " ; if ( check ( str1 , str2 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void FindPairs ( int n , int k ) { Console . Write ( 1 + " ▁ " + n + " STRNEWLINE " ) ; k -- ; for ( long i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { Console . Write ( 1 + " ▁ " + i + " STRNEWLINE " ) ; k -- ; if ( k == 0 ) break ; if ( i != n / i ) { Console . Write ( 1 + " ▁ " + n / i + " STRNEWLINE " ) ; k -- ; } if ( k == 0 ) break ; } } } public static void Main ( String [ ] args ) { int N = 100 ; int K = 5 ; FindPairs ( N , K ) ; } }

Accumulator variables: i, k
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void dfs ( int u , List < int > [ ] adj , int [ ] vis , int [ ] inDeg , int [ ] outDeg ) { vis [ u ] = 1 ; foreach ( int v in adj [ u ] ) { outDeg [ u ] = 1 ; inDeg [ v ] = 1 ; if ( vis [ v ] == 0 ) { dfs ( v , adj , vis , inDeg , outDeg ) ; } } } static int findMinimumEdges ( int [ ] source , int N , int M , int [ ] dest ) { List < int > [ ] adj = new List < int > [ N + 1 ] ; for ( int i = 0 ; i < adj . Length ; i ++ ) adj [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < M ; i ++ ) { adj ] . Add ( dest [ i ] ) ; } int [ ] inDeg = new int [ N + 1 ] ; int [ ] outDeg = new int [ N + 1 ] ; int [ ] vis = new int [ N + 1 ] ; dfs ( 1 , adj , vis , inDeg , outDeg ) ; int minEdges = 0 ; int totalIndegree = 0 ; int totalOutdegree = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( inDeg [ i ] == 1 ) totalIndegree ++ ; if ( outDeg [ i ] == 1 ) totalOutdegree ++ ; } minEdges = Math . Max ( N - totalIndegree , N - totalOutdegree ) ; return minEdges ; } public static void Main ( String [ ] args ) { int N = 5 , M = 5 ; int [ ] source = { 1 , 3 , 1 , 3 , 4 } ; int [ ] destination = { 2 , 2 , 3 , 4 , 5 } ; Console . Write ( findMinimumEdges ( source , N , M , destination ) ) ; } }

Index/key variables: i, u, v
Accumulator variables: i, totalIndegree, totalOutdegree
Iterator variables: i, v
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int PermuteTheArray ( int [ ] A , int n ) { int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ A [ i ] - 1 ] = i ; } int mini = n , maxi = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mini = Math . Min ( mini , arr [ i ] ) ; maxi = Math . Max ( maxi , arr [ i ] ) ; if ( maxi - mini == i ) count ++ ; } return count ; } public static void Main ( String [ ] args ) { int [ ] A = { 4 , 5 , 1 , 3 , 2 , 6 } ; Console . Write ( PermuteTheArray ( A , 6 ) ) ; } }

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