dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static void countString ( string S ) { int count = 0 ; foreach ( char it in S ) { if ( it == '0' && count > 0 ) { count -- ; } else { count ++ ; } } Console . Write ( ( 1 << count ) - 1 ) ; } public static void Main ( string [ ] args ) { string S = "1001" ; countString ( S ) ; } }

Accumulator variables: count
Iterator variables: it
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void replaceDuplicates ( string [ ] names ) { Dictionary < string , int > hash = new Dictionary < string , int > ( ) ; for ( int i = 0 ; i < names . Length ; i ++ ) { if ( ! hash . ContainsKey ( names [ i ] ) ) hash [ names [ i ] ] = 1 ; else { int count = hash [ names [ i ] ] ; hash [ names [ i ] ] += 1 ; names [ i ] += count . ToString ( ) ; } } for ( int i = 0 ; i < names . Length ; i ++ ) { Console . Write ( names [ i ] + ' ▁ ' ) ; } } public static void Main ( ) { string [ ] str = { " aa " , " bb " , " cc " , " bb " , " aa " , " aa " , " aa " } ; replaceDuplicates ( str ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static void convert_to_allzeroes ( string str , int a , int b ) { int len = str . Length ; int left_1 , i = 0 ; while ( i < len && str [ i ] == '0' ) i ++ ; left_1 = i ; int right_1 ; i = len - 1 ; while ( i >= 0 && str [ i ] == '0' ) i -- ; right_1 = i ; if ( left_1 == len && right_1 == - 1 ) { Console . Write ( 0 ) ; return ; } int cost = a , zeroes ; for ( i = left_1 ; i <= right_1 ; i ++ ) { zeroes = 0 ; while ( i < len && str [ i ] == '0' ) { zeroes ++ ; i ++ ; } if ( zeroes != 0 ) cost += Math . Min ( zeroes * b , a ) ; } Console . Write ( cost ) ; } public static void Main ( ) { string str = "01101110" ; int A = 5 , B = 1 ; convert_to_allzeroes ( str , A , B ) ; } }

Index/key variables: i
Accumulator variables: cost, i, zeroes
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MinDistK ( int [ ] arr , int N , int K ) { int res = Int32 . MaxValue ; int dist = 0 ; for ( int i = 0 ; i <= ( N - K ) ; i ++ ) { if ( arr [ i ] >= 0 && arr [ i + K - 1 ] >= 0 ) { dist = Math . Max ( arr [ i ] , arr [ i + K - 1 ] ) ; } else { dist = Math . Abs ( arr [ i ] ) + Math . Abs ( arr [ i + K - 1 ] ) + Math . Min ( Math . Abs ( arr [ i ] ) , Math . Abs ( arr [ i + K - 1 ] ) ) ; } res = Math . Min ( res , dist ) ; } return res ; } public static void Main ( ) { int K = 3 ; int [ ] arr = { - 30 , - 10 , 10 , 20 , 50 } ; int N = arr . Length ; Console . WriteLine ( MinDistK ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int min1 ( int [ ] a , int n ) { int minIndex = 0 , minValue = a [ 0 ] , i ; for ( i = 1 ; i < n ; i ++ ) { if ( a [ i ] < minValue ) { minValue = a [ i ] ; minIndex = i ; } } return minIndex ; } static int maximizeMin ( int [ ] A , int N , int S , int M ) { int minIndex , left , right , i , j ; for ( i = 0 ; i < M ; i ++ ) { minIndex = min1 ( A , N ) ; A [ minIndex ] ++ ; left = minIndex - 1 ; right = minIndex + 1 ; for ( j = 0 ; j < S - 1 ; j ++ ) { if ( left == - 1 ) A [ right ++ ] ++ ; else if ( right == N ) A [ left -- ] ++ ; else { if ( A [ left ] < A [ right ] ) A [ left -- ] ++ ; else A [ right ++ ] ++ ; } } } minIndex = min1 ( A , N ) ; return A [ minIndex ] ; } static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 } ; int N = arr . Length ; int S = 2 , M = 3 ; Console . Write ( maximizeMin ( arr , N , S , M ) ) ; } }

Index/key variables: i, left, minIndex, right
Accumulator variables: i, j, left, right
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int sumOfPathNodes ( int N ) { if ( N == 1 ) { return 1 ; } else if ( N == 2 N == 3 ) { return N + 1 ; } List < int > arr = new List < int > ( ) ; arr . Add ( 1 ) ; int k = 1 ; bool flag = true ; while ( k < N ) { if ( flag == true ) { k *= 2 ; flag = false ; } else { k *= 4 ; flag = true ; } if ( k > N ) { break ; } arr . Add ( k ) ; } int len = arr . Count ; int [ ] prefix = new int [ len ] ; prefix [ 0 ] = 1 ; for ( int i = 1 ; i < len ; ++ i ) { prefix [ i ] = arr [ i ] + prefix [ i - 1 ] ; } int it = lowerBound ( prefix , 0 , len , N ) + 1 ; int ind = it - prefix [ 0 ] ; int final_ans = 0 ; int temp = N ; while ( ind > 1 ) { int val = temp - prefix [ ind - 1 ] ; if ( ind % 2 != 0 ) { temp = prefix [ ind - 2 ] + ( val + 1 ) / 2 ; } else { temp = prefix [ ind - 2 ] + ( val + 3 ) / 4 ; } -- ind ; final_ans += temp ; } final_ans += ( N + 1 ) ; return final_ans ; } static int lowerBound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } public static void Main ( String [ ] args ) { int N = 13 ; Console . Write ( sumOfPathNodes ( N ) + " STRNEWLINE " ) ; } }

Index/key variables: i, len, middle
Accumulator variables: final_ans, k
Iterator variables: i
Boolean variables: flag
Class/struct names: GFG
C# program:
using System ; class GFG { static bool checkPointRange ( int [ , ] arr , int X , int Y , int N ) { for ( int i = 0 ; i < N ; i ++ ) { double dist = Math . Sqrt ( ( arr [ i , 0 ] - X ) * ( arr [ i , 0 ] - X ) + ( arr [ i , 1 ] - Y ) * ( arr [ i , 1 ] - Y ) ) ; if ( dist <= arr [ i , 2 ] ) { return true ; } } return false ; } public static void Main ( ) { int [ , ] arr = { { 1 , 1 , 3 } , { 10 , 10 , 3 } , { 15 , 15 , 15 } } ; int X = 5 , Y = 5 ; int N = arr . Length ; if ( checkPointRange ( arr , X , Y , N ) ) { Console . Write ( " True " ) ; } else { Console . Write ( " False " ) ; } } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void findWinner ( int [ ] arr , int N ) { int odd = 0 ; int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 1 ) { odd ++ ; } else { even ++ ; } } if ( even == 0 ) { if ( odd % 2 == 0 ) { Console . WriteLine ( " Player ▁ 2" ) ; } else if ( odd % 2 == 1 ) { Console . WriteLine ( " Player ▁ 1" ) ; } } else if ( even == 1 && odd % 2 == 1 ) { Console . WriteLine ( " Player ▁ 1" ) ; } else { Console . WriteLine ( - 1 ) ; } } public static void Main ( ) { int [ ] arr = { 3 , 1 , 9 , 7 } ; int N = arr . Length ; findWinner ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: even, i, odd
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void rearrangeArrMaxcntMinima ( int [ ] arr , int N ) { Array . Sort ( arr ) ; int left = 0 ; int right = N / 2 ; while ( left < N / 2 right < N ) { if ( right < N ) { Console . Write ( arr [ right ] + " ▁ " ) ; right ++ ; } if ( left < N / 2 ) { Console . Write ( arr [ left ] + " ▁ " ) ; left ++ ; } } } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int N = arr . Length ; rearrangeArrMaxcntMinima ( arr , N ) ; } }

Index/key variables: left, right
Accumulator variables: left, right
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int MOD = ( int ) 1e9 + 7 ; static int minJumps ( String seats ) { List < int > position = new List < int > ( ) ; int count = 0 ; int len = seats . Length ; for ( int i = 0 ; i < len ; i ++ ) { if ( seats [ i ] == ' x ' ) { position . Add ( i - count ) ; count ++ ; } } if ( count == len count == 0 ) return 0 ; int med_index = ( count - 1 ) / 2 ; int med_val = position [ med_index ] ; int ans = 0 ; for ( int i = 0 ; i < position . Count ; i ++ ) { ans = ( ans % MOD + Math . Abs ( position [ i ] - med_val ) % MOD ) % MOD ; } return ans % MOD ; } public static void Main ( String [ ] args ) { String S = " . . . . x . . xx . . . x . . " ; Console . Write ( minJumps ( S ) ) ; } }

Index/key variables: i, med_index
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int singlePrimeFactor ( int N ) { HashSet < int > disPrimeFact = new HashSet < int > ( ) ; for ( int i = 2 ; i * i <= N ; ++ i ) { while ( N % i == 0 ) { disPrimeFact . Add ( i ) ; N /= i ; } } if ( N != 1 ) { disPrimeFact . Add ( N ) ; } if ( disPrimeFact . Count == 1 ) { foreach ( int i in disPrimeFact ) return i ; } return - 1 ; } static int cntsingleFactorPair ( int [ ] arr , int N ) { int countOf1 = 0 ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == 1 ) { countOf1 ++ ; continue ; } int factorValue = singlePrimeFactor ( arr [ i ] ) ; if ( factorValue == - 1 ) { continue ; } else { if ( mp . ContainsKey ( factorValue ) ) mp [ factorValue ] = mp [ factorValue ] + 1 ; else mp . Add ( factorValue , 1 ) ; } } int res = 0 ; foreach ( KeyValuePair < int , int > ele1 in mp ) { int X = ele1 . Value ; res += countOf1 * X + ( X * ( X - 1 ) ) / 2 ; } return res ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 } ; int N = arr . Length ; Console . WriteLine ( cntsingleFactorPair ( arr , N ) ) ; } }

Index/key variables: factorValue, i
Accumulator variables: N, countOf1, i, res
Iterator variables: ele1, i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MincntBothPalin ( string str1 , string str2 , int N ) { int i = 0 ; int j = N - 1 ; int cntOp = 0 ; while ( i < j ) { if ( str1 [ i ] == str1 [ j ] && str2 [ i ] != str2 [ j ] ) { cntOp += 1 ; } else if ( str1 [ i ] != str1 [ j ] && str2 [ i ] == str2 [ j ] ) { cntOp += 1 ; } else if ( str1 [ i ] != str1 [ j ] && str2 [ i ] != str2 [ j ] ) { if ( str1 [ i ] == str2 [ j ] && str2 [ i ] == str1 [ j ] ) { cntOp += 1 ; } else { cntOp += 2 ; } } i += 1 ; j -= 1 ; } return cntOp ; } public static void Main ( ) { string str1 = " dbba " ; string str2 = " abcd " ; int N = str1 . Length ; Console . WriteLine ( MincntBothPalin ( str1 , str2 , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: cntOp, i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int power ( int x , int N ) { int res = 1 ; while ( N > 0 ) { if ( ( N & 1 ) != 0 ) { res = ( res * x ) ; } x = ( x * x ) ; N = N >> 1 ; } return res ; } static void findValX_Y ( int N ) { if ( N <= 1 ) { Console . WriteLine ( - 1 ) ; return ; } int xMax ; xMax = ( int ) Math . Log ( N ) ; int yMax ; yMax = ( int ) ( Math . Log ( N ) / Math . Log ( 5.0 ) ) ; for ( int i = 1 ; i <= xMax ; i ++ ) { for ( int j = 1 ; j <= yMax ; j ++ ) { int a = power ( 2 , i ) ; int b = power ( 5 , j ) ; if ( a + b == N ) { Console . Write ( i + " ▁ " + j ) ; return ; } } } Console . WriteLine ( " - 1" ) ; } public static void Main ( ) { int N = 129 ; findValX_Y ( N ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int countPairs ( int [ ] v1 , int [ ] v2 , int n , int m , int k ) { int count = 0 ; if ( n <= m ) { Array . Sort ( v1 ) ; for ( int j = 0 ; j < m ; j ++ ) { int index = lowerBound ( v1 , 0 , n , v2 [ j ] - k ) ; count += index ; } } else { Array . Sort ( v2 ) ; for ( int i = 0 ; i < n ; i ++ ) { int index = upperBound ( v2 , 0 , m , v1 [ i ] + k ) ; count += m - index ; } } return count ; } static int lowerBound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( element > a [ middle ] ) low = middle + 1 ; else high = middle ; } return low ; } static int upperBound ( int [ ] a , int low , int high , int element ) { while ( low < high ) { int middle = low + ( high - low ) / 2 ; if ( a [ middle ] > element ) high = middle ; else low = middle + 1 ; } return low ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 9 , 1 , 8 } ; int [ ] brr = { 10 , 12 , 7 , 4 , 2 , 3 } ; int K = 3 ; int N = arr . Length ; int M = brr . Length ; Console . Write ( countPairs ( arr , brr , N , M , K ) ) ; } }

Index/key variables: i, j, middle
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { public class Node { public int key ; public List < Node > child = new List < Node > ( ) ; } ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; return temp ; } static void Siblings ( Node root , int value ) { int flag = 0 ; if ( root == null ) return ; Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; while ( q . Count != 0 ) { Node temp = q . Peek ( ) ; q . Dequeue ( ) ; for ( int i = 0 ; i < temp . child . Count ; i ++ ) { if ( temp . child [ i ] . key == value ) { flag = 1 ; for ( int j = 0 ; j < temp . child . Count ; j ++ ) { if ( value != temp . child [ j ] . key ) Console . Write ( temp . child [ j ] . key + " ▁ " ) ; } break ; } q . Enqueue ( temp . child [ i ] ) ; } } if ( flag == 0 ) Console . Write ( " No ▁ siblings ! ! " ) ; } static Node constructTree ( ) { Node root = newNode ( 10 ) ; ( root . child ) . Add ( newNode ( 20 ) ) ; ( root . child ) . Add ( newNode ( 30 ) ) ; ( root . child ) . Add ( newNode ( 40 ) ) ; ( root . child [ 0 ] . child ) . Add ( newNode ( 50 ) ) ; ( root . child [ 0 ] . child ) . Add ( newNode ( 60 ) ) ; ( root . child [ 1 ] . child ) . Add ( newNode ( 70 ) ) ; ( root . child [ 1 ] . child ) . Add ( newNode ( 80 ) ) ; ( root . child [ 2 ] . child ) . Add ( newNode ( 90 ) ) ; ( root . child [ 2 ] . child ) . Add ( newNode ( 100 ) ) ; ( root . child [ 2 ] . child ) . Add ( newNode ( 110 ) ) ; return root ; } public static void Main ( String [ ] args ) { Node root = constructTree ( ) ; int X = 30 ; Siblings ( root , X ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, Node
C# program:
using System ; class GFG { private static void maxSumSubarr ( int [ ] A , int N , int K , int X ) { int sum_K = 0 ; for ( int i = 0 ; i < K ; i ++ ) { sum_K += A [ i ] ; } int Max_Sum = 0 ; if ( sum_K < X ) { Max_Sum = sum_K ; } for ( int i = K ; i < N ; i ++ ) { sum_K -= ( A [ i - K ] - A [ i ] ) ; if ( sum_K < X ) { Max_Sum = Math . Max ( Max_Sum , sum_K ) ; } } Console . WriteLine ( Max_Sum ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { - 5 , 8 , 7 , 2 , 10 , 1 , 20 , - 4 , 6 , 9 } ; int K = 5 ; int X = 30 ; int N = arr . Length ; maxSumSubarr ( arr , N , K , X ) ; } }

Index/key variables: i
Accumulator variables: i, sum_K
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static void rearrangeArray ( int [ ] a , int N ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; } if ( sum == 0 ) { Console . Write ( " - 1" ) ; return ; } sum = 0 ; int b = 0 ; Array . Sort ( a ) ; for ( int i = 0 ; i < N ; i ++ ) { sum += a [ i ] ; if ( sum == 0 ) { if ( a [ i ] != a [ N - 1 ] ) { sum -= a [ i ] ; int temp = a [ i ] ; a [ i ] = a [ N - 1 ] ; a [ N - 1 ] = temp ; sum += a [ i ] ; } else { b = 1 ; break ; } } } if ( b == 1 ) { b = 0 ; sum = 0 ; Array . Sort ( a ) ; for ( int i = N - 1 ; i >= 0 ; i -- ) { sum += a [ i ] ; if ( sum == 0 ) { if ( a [ i ] != a [ 0 ] ) { sum -= a [ i ] ; int temp = a [ i ] ; a [ i ] = a [ 0 ] ; a [ 0 ] = temp ; sum += a [ i ] ; } else { b = 1 ; break ; } } } } if ( b == 1 ) { Console . Write ( " - 1" + " ▁ " ) ; return ; } for ( int i = 0 ; i < N ; i ++ ) { Console . Write ( a [ i ] + " ▁ " ) ; } } public static void Main ( ) { int [ ] arr = { 1 , - 1 , 2 , 4 , 0 } ; int N = arr . Length ; rearrangeArray ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void removeSmallestSubarray ( int [ ] arr , int n , int k ) { int [ ] mod_arr = new int [ n ] ; int total_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mod_arr [ i ] = ( arr [ i ] + k ) % k ; total_sum += arr [ i ] ; } int target_remainder = total_sum % k ; if ( target_remainder == 0 ) { Console . Write ( "0" ) ; return ; } Dictionary < int , int > map1 = new Dictionary < int , int > ( ) ; map1 . Add ( 0 , - 1 ) ; int curr_remainder = 0 ; int res = int . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { curr_remainder = ( curr_remainder + arr [ i ] + k ) % k ; map1 [ curr_remainder ] = i ; int mod = ( curr_remainder - target_remainder + k ) % k ; if ( map1 . ContainsKey ( mod ) ) res = Math . Min ( res , i - map1 [ mod ] ) ; } if ( res == int . MaxValue res == n ) { res = - 1 ; } Console . Write ( res ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 1 , 4 , 2 } ; int N = arr . Length ; int K = 6 ; removeSmallestSubarray ( arr , N , K ) ; } }

Index/key variables: curr_remainder, i, mod, n
Accumulator variables: i, total_sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static String toggleQuery ( char [ ] str , int [ , ] Q , int M ) { int N = str . Length ; int [ ] prefixCnt = new int [ N + 1 ] ; for ( int i = 0 ; i < M ; i ++ ) { prefixCnt [ Q [ i , 0 ] ] += 1 ; prefixCnt [ Q [ i , 1 ] + 1 ] -= 1 ; } for ( int i = 1 ; i <= N ; i ++ ) { prefixCnt [ i ] += prefixCnt [ i - 1 ] ; } for ( int i = 0 ; i < N ; i ++ ) { if ( prefixCnt [ i ] % 2 == 1 ) { str [ i ] = ( char ) ( '1' - str [ i ] + '0' ) ; } } return String . Join ( " " , str ) ; } public static void Main ( String [ ] args ) { String str = "101010" ; int [ , ] Q = { { 0 , 1 } , { 2 , 5 } , { 2 , 3 } , { 1 , 4 } , { 0 , 5 } } ; int M = Q . GetLength ( 0 ) ; Console . Write ( toggleQuery ( str . ToCharArray ( ) , Q , M ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Linq ; class GFG { static bool isValid ( int [ ] wood , int N , int len , int K ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { count += wood [ i ] / len ; } return count >= K ; } static int findMaxLen ( int [ ] wood , int N , int K ) { int left = 1 ; int right = wood . Max ( ) ; while ( left <= right ) { int mid = left + ( right - left ) / 2 ; if ( isValid ( wood , N , mid , K ) ) { left = mid + 1 ; } else { right = mid - 1 ; } } return right ; } public static void Main ( String [ ] args ) { int [ ] wood = { 5 , 9 , 7 } ; int N = wood . Length ; int K = 4 ; Console . Write ( findMaxLen ( wood , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG
C# program:
class GFG { static int countSum ( int [ ] a , int n , int sum ) { int i , j , k , l ; int count = 0 ; for ( i = 0 ; i < n - 3 ; i ++ ) { for ( j = i + 1 ; j < n - 2 ; j ++ ) { for ( k = j + 1 ; k < n - 1 ; k ++ ) { for ( l = k + 1 ; l < n ; l ++ ) { if ( a [ i ] + a [ j ] + a [ k ] + a [ l ] == sum ) count ++ ; } } } } return count ; } public static void Main ( ) { int [ ] arr = { 4 , 5 , 3 , 1 , 2 , 4 } ; int S = 13 ; int N = arr . Length ; System . Console . Write ( countSum ( arr , N , S ) ) ; } }

Index/key variables: i, j, k, l
Accumulator variables: count, i, j, k, l
Iterator variables: i, j, k, l
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int minSwaps ( String S , int n ) { int swaps = 0 ; List < int > [ ] arr = new List < int > [ 26 ] ; for ( int i = 0 ; i < arr . Length ; i ++ ) arr [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { int pos = S [ i ] - ' a ' ; arr [ pos ] . Add ( i ) ; } for ( char ch = ' a ' ; ch <= ' z ' ; ++ ch ) { int pos = ch - ' a ' ; for ( int i = 1 ; i < arr [ pos ] . Count ; ++ i ) { swaps += Math . Abs ( arr [ pos ] [ i ] - arr [ pos ] [ i - 1 ] - 1 ) ; } } return swaps ; } public static void Main ( String [ ] args ) { String S = " abbccabbcc " ; int N = S . Length ; Console . Write ( minSwaps ( S , N ) ) ; } }

Index/key variables: i, pos
Accumulator variables: i, swaps
Iterator variables: ch, i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { public class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void printConnections ( List < pair > store , List < int > ind , int ind1 ) { foreach ( pair pr in store ) { Console . Write ( pr . first + " ▁ " + pr . second + " STRNEWLINE " ) ; } if ( ind . Count != 0 ) { foreach ( int x in ind ) { Console . Write ( ind1 + " ▁ " + ( x + 1 ) + " STRNEWLINE " ) ; } } } static void constructGraph ( char [ ] arr , int N ) { List < int > ind = new List < int > ( ) ; List < pair > store = new List < pair > ( ) ; char x = arr [ 0 ] ; int count = 0 ; int ind1 = - 1 ; for ( int i = 1 ; i <= N - 1 ; ++ i ) { if ( arr [ i ] != x ) { ind1 = i + 1 ; count ++ ; store . Add ( new pair ( 1 , i + 1 ) ) ; } else { ind . Add ( i ) ; } } if ( count == 0 ) { Console . Write ( " Not ▁ Possible " ) ; } else { Console . Write ( " Possible " + " STRNEWLINE " ) ; printConnections ( store , ind , ind1 ) ; } } public static void Main ( String [ ] args ) { int N = 5 ; char [ ] arr = { ' a ' , ' b ' , ' a ' , ' b ' , ' c ' } ; constructGraph ( arr , N ) ; } }

Index/key variables: i
Accumulator variables: count
Iterator variables: i, pr, x
Class/struct names: GFG, pair
C# program:
using System ; class GFG { static void findMinimumOperations ( string a , string b ) { int step = 0 ; int last_index = 0 ; while ( a . Equals ( b ) == false ) { for ( int i = 0 ; i < a . Length ; i ++ ) { if ( a [ i ] != b [ i ] ) { last_index = i ; } } char [ ] ch = a . ToCharArray ( ) ; for ( int i = 0 ; i <= last_index ; i ++ ) { if ( ch [ i ] == '0' ) { ch [ i ] = '1' ; } else { ch [ i ] = '0' ; } } a = new string ( ch ) ; step ++ ; } Console . WriteLine ( step ) ; } public static void Main ( ) { string A = "101010" ; string B = "110011" ; findMinimumOperations ( A , B ) ; } }

Index/key variables: i
Accumulator variables: i, step
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int isValid ( int [ ] arr , int n , int m , int d ) { for ( int i = 0 ; i < m ; i ++ ) { if ( Math . Abs ( arr [ n - m + i ] - arr [ i ] ) < d ) { return 0 ; } } return 1 ; } static void countPairs ( int [ ] arr , int N , int K ) { int ans = 0 ; int left = 0 , right = N / 2 + 1 ; Array . Sort ( arr ) ; while ( left < right ) { int mid = ( left + right ) / 2 ; if ( isValid ( arr , N , mid , K ) == 1 ) { ans = mid ; left = mid + 1 ; } else right = mid - 1 ; } Console . WriteLine ( ans ) ; } public static void Main ( ) { int [ ] arr = { 1 , 3 , 3 , 5 } ; int K = 2 ; int N = arr . Length ; countPairs ( arr , N , K ) ; } }

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