dhyuti-n/xlcost-variable-roles huggingface dataset:
C# program:
using System ; class GFG { static int findGCDSum ( int n , int [ ] a ) { int GCDSum = 0 ; int tempGCD = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { tempGCD = 0 ; for ( int k = i ; k <= j ; k ++ ) { tempGCD = __gcd ( tempGCD , a [ k ] ) ; } GCDSum += tempGCD ; } } return GCDSum ; } static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } public static void Main ( String [ ] args ) { int n = 5 ; int [ ] a = { 1 , 2 , 3 , 4 , 5 } ; int totalSum = findGCDSum ( n , a ) ; Console . Write ( totalSum + " STRNEWLINE " ) ; } }

Index/key variables: k
Accumulator variables: GCDSum, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
C# program:
using System ; class GFG { static bool containsElement ( int [ ] arr , int n ) { int xorArr = 0 ; for ( int i = 0 ; i < n ; ++ i ) xorArr ^= arr [ i ] ; for ( int i = 0 ; i < n ; ++ i ) { int x = xorArr ^ arr [ i ] ; if ( arr [ i ] == x ) return true ; } return false ; } public static void Main ( ) { int [ ] arr = { 8 , 2 , 4 , 15 , 1 } ; int n = arr . Length ; if ( containsElement ( arr , n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }

Index/key variables: i
Accumulator variables: xorArr
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int length_substring ( string S , char K ) { int curr_cnt = 0 , prev_cnt = 0 , max_len ; for ( int i = 0 ; i < S . Length ; i ++ ) { if ( S [ i ] == K ) { curr_cnt += 1 ; } else { prev_cnt = Math . Max ( prev_cnt , curr_cnt ) ; curr_cnt = 0 ; } } prev_cnt = Math . Max ( prev_cnt , curr_cnt ) ; max_len = prev_cnt ; return max_len ; } static public void Main ( ) { string S = " abcd1111aabc " ; char K = '1' ; Console . WriteLine ( length_substring ( S , K ) ) ; } }

Index/key variables: i
Accumulator variables: curr_cnt, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { public static int Xor_Sum ( int [ ] arr , int n ) { int sum = 0 , index = - 1 ; int left_xor = 0 , right_xor = 0 ; for ( int i = 0 ; i < n ; i ++ ) { left_xor = left_xor ^ arr [ i ] ; right_xor = 0 ; for ( int j = i + 1 ; j < n ; j ++ ) { right_xor = right_xor ^ arr [ j ] ; } if ( left_xor + right_xor > sum ) { sum = left_xor + right_xor ; index = i ; } } return index + 1 ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 } ; int n = arr . Length ; Console . WriteLine ( Xor_Sum ( arr , 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 void ComputePrefixXor ( int [ ] arr , int [ ] PrefixXor , int n ) { PrefixXor [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) PrefixXor [ i ] = PrefixXor [ i - 1 ] ^ arr [ i ] ; } static int Xor_Sum ( int [ ] arr , int n ) { int [ ] PrefixXor = new int [ n ] ; ComputePrefixXor ( arr , PrefixXor , n ) ; int sum = 0 , index = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) > sum ) { sum = PrefixXor [ i ] + ( PrefixXor [ n - 1 ] ^ PrefixXor [ i ] ) ; index = i ; } } return index + 1 ; } public static void Main ( ) { int [ ] arr = { 1 , 4 , 6 , 3 , 8 , 13 , 34 , 2 , 21 , 10 } ; int n = arr . Length ; Console . WriteLine ( Xor_Sum ( arr , n ) ) ; } }

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 int findColor ( Dictionary < int , int > mapWithColor , int query ) { int maximum = 0 ; while ( query >= 1 ) { if ( mapWithColor . ContainsKey ( query ) ) { maximum = Math . Max ( maximum , mapWithColor [ query ] ) ; } if ( query % 2 == 1 ) query = ( query - 1 ) / 2 ; else query = query / 2 ; } return maximum ; } static Dictionary < int , int > buildMapWithColor ( int [ ] arr , int n ) { Dictionary < int , int > mapWithColor = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mapWithColor . ContainsKey ( arr [ i ] ) ) mapWithColor [ arr [ i ] ] = i + 1 ; else mapWithColor . Add ( arr [ i ] , i + 1 ) ; } return mapWithColor ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 1 , 3 } ; int n = arr . Length ; int k = 7 ; Dictionary < int , int > mapWithColor = buildMapWithColor ( arr , n ) ; Console . Write ( findColor ( mapWithColor , k ) ) ; } }

Index/key variables: i, query
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; public class GFG { static int MAX = 26 ; static List < int > findCount ( String [ ] a , String [ ] b , int n , int m ) { int [ ] freq = new int [ MAX ] ; List < int > smallestFreq = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { String s = a [ i ] ; for ( int l = 0 ; l < freq . Length ; l ++ ) freq [ l ] = 0 ; for ( int j = 0 ; j < s . Length ; j ++ ) { freq [ s [ j ] - ' a ' ] ++ ; } for ( int j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { smallestFreq . Add ( freq [ j ] ) ; break ; } } } smallestFreq . Sort ( ) ; List < int > ans = new List < int > ( ) ; for ( int i = 0 ; i < m ; i ++ ) { String s = b [ i ] ; for ( int l = 0 ; l < freq . Length ; l ++ ) freq [ l ] = 0 ; for ( int j = 0 ; j < s . Length ; j ++ ) { freq [ s [ j ] - ' a ' ] ++ ; } int frequency = 0 ; for ( int j = 0 ; j < MAX ; j ++ ) { if ( freq [ j ] > 0 ) { frequency = freq [ j ] ; break ; } } int [ ] array = new int [ smallestFreq . Count ] ; int k = 0 ; foreach ( int val in smallestFreq ) { array [ k ] = val ; k ++ ; } int ind = lower_bound ( array , 0 , smallestFreq . Count , frequency ) ; ans . Add ( ind ) ; } return ans ; } static int lower_bound ( 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 void printAnswer ( String [ ] a , String [ ] b , int n , int m ) { List < int > ans = findCount ( a , b , n , m ) ; foreach ( int it in ans ) { Console . Write ( it + " ▁ " ) ; } } public static void Main ( String [ ] args ) { String [ ] A = { " aaa " , " aa " , " bdc " } ; String [ ] B = { " cccch " , " cccd " } ; int n = A . Length ; int m = B . Length ; printAnswer ( A , B , n , m ) ; } }

Index/key variables: MAX, i, j, k, l, middle
Accumulator variables: i, j, k, l
Iterator variables: i, it, j, l, val
Class/struct names: GFG
C# program:
using System ; class GFG { static void LeftRightNode ( int [ ] preorder , int n ) { int min = int . MaxValue , max = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( min > preorder [ i ] ) min = preorder [ i ] ; if ( max < preorder [ i ] ) max = preorder [ i ] ; } Console . WriteLine ( " Leftmost ▁ node ▁ is ▁ " + min ) ; Console . WriteLine ( " Rightmost ▁ node ▁ is ▁ " + max ) ; } public static void Main ( String [ ] args ) { int [ ] preorder = { 3 , 2 , 1 , 5 , 4 } ; int n = 5 ; LeftRightNode ( preorder , n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int m = 6 , n = 4 ; static int compareRow ( int [ ] a1 , int [ ] a2 ) { for ( int i = 0 ; i < n ; i ++ ) { if ( a1 [ i ] < a2 [ i ] ) return 1 ; else if ( a1 [ i ] > a2 [ i ] ) return - 1 ; } return 0 ; } static int binaryCheck ( int [ , ] ar , int [ ] arr ) { int l = 0 , r = m - 1 ; while ( l <= r ) { int mid = ( l + r ) / 2 ; int temp = compareRow ( GetRow ( ar , mid ) , arr ) ; if ( temp == 0 ) return mid + 1 ; else if ( temp == 1 ) l = mid + 1 ; else r = mid - 1 ; } return - 1 ; } public static int [ ] GetRow ( int [ , ] matrix , int row ) { var rowLength = matrix . GetLength ( 1 ) ; var rowVector = new int [ rowLength ] ; for ( var i = 0 ; i < rowLength ; i ++ ) rowVector [ i ] = matrix [ row , i ] ; return rowVector ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 0 , 0 , 1 , 0 } , { 10 , 9 , 22 , 23 } , { 40 , 40 , 40 , 40 } , { 43 , 44 , 55 , 68 } , { 81 , 73 , 100 , 132 } , { 100 , 75 , 125 , 133 } } ; int [ ] row = { 10 , 9 , 22 , 23 } ; Console . WriteLine ( binaryCheck ( mat , row ) ) ; } }

Index/key variables: i, rowLength
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int findCnt ( int [ ] arr , int n , int k ) { int ans = 0 ; for ( int i = 1 ; i < n ; i ++ ) { arr [ i ] += arr [ i - 1 ] ; if ( arr [ i ] > k arr [ i ] < - 1 * k ) ans ++ ; } if ( arr [ 0 ] > k arr [ 0 ] < - 1 * k ) ans ++ ; Array . Sort ( arr ) ; for ( int i = 0 ; i < n ; i ++ ) ans += n - upper_bound ( arr , 0 , n , arr [ i ] + k ) ; return ans ; } static int upper_bound ( 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 ( ) { int [ ] arr = { - 1 , 4 , - 5 , 6 } ; int n = arr . Length ; int k = 0 ; Console . WriteLine ( findCnt ( arr , n , k ) ) ; } }

Index/key variables: i, middle
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static int upperBound ( List < 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 ; } static int FindIntersection ( List < List < int > > type1 , int n , List < List < int > > type2 , int m ) { int ans = n * m ; List < int > start = new List < int > ( ) ; List < int > end = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { start . Add ( type1 [ i ] [ 0 ] ) ; end . Add ( type1 [ i ] [ 1 ] ) ; } start . Sort ( ) ; end . Sort ( ) ; for ( int i = 0 ; i < m ; i ++ ) { int L = type2 [ i ] [ 0 ] ; int R = type2 [ i ] [ 1 ] ; ans -= start . Count - upperBound ( start , 0 , start . Count , R ) ; ans -= upperBound ( end , 0 , end . Count , L - 1 ) ; } return ans ; } static public void Main ( ) { List < List < int > > type1 = new List < List < int > > ( ) ; type1 . Add ( new List < int > ( ) { 1 , 2 } ) ; type1 . Add ( new List < int > ( ) { 2 , 3 } ) ; type1 . Add ( new List < int > ( ) { 4 , 5 } ) ; type1 . Add ( new List < int > ( ) { 6 , 7 } ) ; List < List < int > > type2 = new List < List < int > > ( ) ; type2 . Add ( new List < int > ( ) { 1 , 5 } ) ; type2 . Add ( new List < int > ( ) { 2 , 3 } ) ; type2 . Add ( new List < int > ( ) { 4 , 7 } ) ; type2 . Add ( new List < int > ( ) { 5 , 7 } ) ; int n = type1 . Count ; int m = type2 . Count ; Console . WriteLine ( FindIntersection ( type1 , n , type2 , m ) ) ; } }

Index/key variables: i, middle
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int gcd ( int a , int b ) { if ( a == 0 ) return b ; return gcd ( b % a , a ) ; } static int lcm ( int a , int b ) { return ( a * b ) / gcd ( a , b ) ; } static int divTermCount ( int a , int b , int c , int num ) { return ( ( num / a ) + ( num / b ) + ( num / c ) - ( num / lcm ( a , b ) ) - ( num / lcm ( b , c ) ) - ( num / lcm ( a , c ) ) + ( num / lcm ( a , lcm ( b , c ) ) ) ) ; } static int findNthTerm ( int a , int b , int c , int n ) { int low = 1 , high = int . MaxValue , mid ; while ( low < high ) { mid = low + ( high - low ) / 2 ; if ( divTermCount ( a , b , c , mid ) < n ) low = mid + 1 ; else high = mid ; } return low ; } public static void Main ( String [ ] args ) { int a = 2 , b = 3 , c = 5 , n = 10 ; Console . WriteLine ( findNthTerm ( a , b , c , n ) ) ; } }

Class/struct names: GFG
C# program:
using System ; class GFG { static Boolean check ( int mid , int [ ] array , int n , int K ) { int count = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( array [ i ] > mid ) return false ; sum += array [ i ] ; if ( sum > mid ) { count ++ ; sum = array [ i ] ; } } count ++ ; if ( count <= K ) return true ; return false ; } static int solve ( int [ ] array , int n , int K ) { int start = 1 ; for ( int i = 0 ; i < n ; ++ i ) { if ( array [ i ] > start ) } int end = 0 ; for ( int i = 0 ; i < n ; i ++ ) { } int answer = 0 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( check ( mid , array , n , K ) ) { answer = mid ; end = mid - 1 ; } else { start = mid + 1 ; } } return answer ; } public static void Main ( String [ ] args ) { int [ ] array = { 1 , 2 , 3 , 4 } ; int n = array . Length ; int K = 3 ; Console . WriteLine ( solve ( array , n , K ) ) ; } }

Index/key variables: i
Accumulator variables: count, i, sum
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { static void createSorted ( int [ ] a , int n ) { List < int > b = new List < int > ( ) ; for ( int j = 0 ; j < n ; j ++ ) { if ( b . Count == 0 ) b . Add ( a [ j ] ) ; else { int start = 0 , end = b . Count - 1 ; int pos = 0 ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; if ( b [ mid ] == a [ j ] ) { b . Insert ( ( Math . Max ( 0 , mid + 1 ) ) , a [ j ] ) ; break ; } else if ( b [ mid ] > a [ j ] ) pos = end = mid - 1 ; else pos = start = mid + 1 ; if ( start > end ) { pos = start ; b . Insert ( Math . Max ( 0 , pos ) , a [ j ] ) ; break ; } } } } for ( int i = 0 ; i < n ; i ++ ) Console . Write ( b [ i ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { int [ ] a = { 2 , 5 , 4 , 9 , 8 } ; int n = a . Length ; createSorted ( a , n ) ; } }

Index/key variables: i, j, mid
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static int MAX = 26 ; static Boolean atLeastK ( int [ ] freq , int k ) { for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] != 0 && freq [ i ] < k ) return false ; } return true ; } static void setZero ( int [ ] freq ) { for ( int i = 0 ; i < MAX ; i ++ ) freq [ i ] = 0 ; } static int findlength ( String str , int n , int k ) { int maxLen = 0 ; int [ ] freq = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) { setZero ( freq ) ; for ( int j = i ; j < n ; j ++ ) { freq [ str [ j ] - ' a ' ] ++ ; if ( atLeastK ( freq , k ) ) { maxLen = Math . Max ( maxLen , j - i + 1 ) ; } } } return maxLen ; } public static void Main ( String [ ] args ) { String str = " xyxyyz " ; int n = str . Length ; int k = 2 ; Console . WriteLine ( findlength ( str , n , k ) ) ; } }

Index/key variables: MAX, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; using System . Linq ; class GFG { static Boolean check ( int m , int n , int [ ] arr ) { int [ ] desired = new int [ n ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { desired [ i ] = m ; m -- ; } for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > desired [ i ] desired [ i ] < 1 ) { return false ; } } return true ; } static int minOperations ( int [ ] arr , int n ) { int start = ( int ) arr [ n - 1 ] ; int end = arr . Max ( ) + n ; int max_arr = 0 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( check ( mid , n , arr ) ) { max_arr = mid ; end = mid - 1 ; } else { start = mid + 1 ; } } int [ ] desired = new int [ n ] ; for ( int i = n - 1 ; i >= 0 ; i -- ) { desired [ i ] = max_arr ; max_arr -- ; } int operations = 0 ; for ( int i = 0 ; i < n ; i ++ ) { operations += ( desired [ i ] - arr [ i ] ) ; } return operations ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 4 , 5 , 5 , 7 } ; int n = arr . Length ; Console . WriteLine ( minOperations ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i, m, max_arr, operations
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node next ; } ; static Node head ; static void insert ( Node ref_head , int item ) { Node temp = new Node ( ) ; temp . data = item ; temp . next = ref_head ; head = temp ; } static int countNode ( Node head ) { if ( head == null ) return 0 ; ; HashSet < int > s = new HashSet < int > ( ) ; s . Add ( head . data ) ; int count = 0 ; for ( Node curr = head . next ; curr != null ; curr = curr . next ) { if ( s . Contains ( curr . data ) ) count ++ ; s . Add ( curr . data ) ; } return count ; } public static void Main ( String [ ] args ) { insert ( head , 5 ) ; insert ( head , 7 ) ; insert ( head , 5 ) ; insert ( head , 1 ) ; insert ( head , 7 ) ; Console . WriteLine ( countNode ( head ) ) ; } }

Accumulator variables: count
Iterator variables: curr
Class/struct names: GFG, Node
C# program:
using System ; using System . Collections . Generic ; class GFG { static int minSteps ( int [ ] arr , int n ) { Boolean [ ] v = new Boolean [ n ] ; Queue < int > q = new Queue < int > ( ) ; q . Enqueue ( 0 ) ; int depth = 0 ; while ( q . Count > 0 ) { int x = q . Count ; while ( x -- > 0 ) { int i = q . Peek ( ) ; q . Dequeue ( ) ; if ( v [ i ] ) continue ; if ( i == n - 1 ) return depth ; v [ i ] = true ; if ( i + arr [ i ] < n ) q . Enqueue ( i + arr [ i ] ) ; if ( i - arr [ i ] >= 0 ) q . Enqueue ( i - arr [ i ] ) ; } depth ++ ; } return - 1 ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 1 , 1 , 1 , 1 } ; int n = arr . Length ; Console . WriteLine ( minSteps ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: depth, x
Class/struct names: GFG
C# program:
using System ; class GFG { static int divisorcount ( int elem ) { int ans = 0 ; for ( int i = 1 ; i <= Math . Sqrt ( elem ) ; i ++ ) { if ( elem % i == 0 ) { if ( i * i == elem ) ans ++ ; else ans += 2 ; } } return ans ; } static string findwinner ( int [ ] A , int [ ] B , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { A [ i ] = divisorcount ( A [ i ] ) ; } for ( int i = 0 ; i < M ; i ++ ) { B [ i ] = divisorcount ( B [ i ] ) ; } Array . Sort ( A ) ; Array . Sort ( B ) ; int winA = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int val = A [ i ] ; int start = 0 ; int end = M - 1 ; int index = - 1 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( B [ mid ] <= val ) { index = mid ; start = mid + 1 ; } else { end = mid - 1 ; } } winA += ( index + 1 ) ; } int winB = N * M - winA ; if ( winA > winB ) { return " A " ; } else if ( winB > winA ) { return " B " ; } return " Draw " ; } public static void Main ( ) { int [ ] A = { 4 , 12 , 24 } ; int N = A . Length ; int [ ] B = { 25 , 28 , 13 , 45 } ; int M = B . Length ; Console . Write ( findwinner ( A , B , N , M ) ) ; } }

Index/key variables: i, mid
Accumulator variables: ans, i, winA
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static bool isPossible ( int [ ] box , int [ ] truck , int n , int m , int min_time ) { int temp = 0 ; int count = 0 ; while ( count < m ) { for ( int j = 0 ; j < min_time && temp < n && truck [ count ] >= box [ temp ] ; j += 2 ) temp ++ ; count ++ ; } if ( temp == n ) return true ; return false ; } static int minTime ( int [ ] box , int [ ] truck , int n , int m ) { Array . Sort ( box ) ; Array . Sort ( truck ) ; int l = 0 ; int h = 2 * n ; int min_time = 0 ; while ( l <= h ) { int mid = ( l + h ) / 2 ; if ( isPossible ( box , truck , n , m , mid ) ) { min_time = mid ; h = mid - 1 ; } else l = mid + 1 ; } return min_time ; } public static void Main ( String [ ] args ) { int [ ] box = { 10 , 2 , 16 , 19 } ; int [ ] truck = { 29 , 25 } ; int n = box . Length ; int m = truck . Length ; Console . WriteLine ( " { 0 } " , minTime ( box , truck , n , m ) ) ; } }

Index/key variables: count, temp
Accumulator variables: count, j, temp
Iterator variables: j
Class/struct names: GFG
C# program:
using System ; class GFG { static void solve ( int [ , ] interval , int N , int Q ) { int [ ] Mark = new int [ Q ] ; for ( int i = 0 ; i < N ; i ++ ) { int l = interval [ i , 0 ] - 1 ; int r = interval [ i , 1 ] - 1 ; for ( int j = l ; j <= r ; j ++ ) Mark [ j ] ++ ; } int count = 0 ; for ( int i = 0 ; i < Q ; i ++ ) { if ( Mark [ i ] != 0 ) count ++ ; } int [ ] count1 = new int [ Q ] ; if ( Mark [ 0 ] == 1 ) count1 [ 0 ] = 1 ; for ( int i = 1 ; i < Q ; i ++ ) { if ( Mark [ i ] == 1 ) count1 [ i ] = count1 [ i - 1 ] + 1 ; else count1 [ i ] = count1 [ i - 1 ] ; } int maxindex = 0 ; int maxcoverage = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int l = interval [ i , 0 ] - 1 ; int r = interval [ i , 1 ] - 1 ; int elem1 ; if ( l != 0 ) elem1 = count1 [ r ] - count1 [ l - 1 ] ; else elem1 = count1 [ r ] ; if ( count - elem1 >= maxcoverage ) { maxcoverage = count - elem1 ; maxindex = i ; } } Console . WriteLine ( " Maximum ▁ Coverage ▁ is ▁ " + maxcoverage + " ▁ after ▁ removing ▁ interval ▁ at ▁ index ▁ " + maxindex ) ; } public static void Main ( ) { int [ , ] interval = { { 1 , 4 } , { 4 , 5 } , { 5 , 6 } , { 6 , 7 } , { 3 , 5 } } ; int N = interval . Length ; int Q = 7 ; solve ( interval , N / 2 , Q ) ; } }

Index/key variables: Q, i, j, r
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
C# program:
using System ; class GFG { static bool isPossible ( int [ ] arr , int n , int dist , int k ) { int req = 0 ; int curr = 0 ; int prev = 0 ; for ( int i = 0 ; i < n ; i ++ ) { while ( curr != n && arr [ curr ] - arr [ prev ] <= dist ) { curr ++ ; } req ++ ; if ( curr == n ) { break ; } prev = curr - 1 ; } if ( curr != n ) { return false ; } if ( req <= k ) { return true ; } return false ; } static int minDistance ( int [ ] arr , int n , int k ) { int l = 0 ; int h = arr [ n - 1 ] ; int ans = 0 ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( isPossible ( arr , n , m , k ) ) { ans = m ; h = m - 1 ; } else { l = m + 1 ; } } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 15 , 36 , 43 } ; int n = arr . Length ; int k = 2 ; Console . WriteLine ( minDistance ( arr , n , k ) ) ; } }

Index/key variables: curr, prev
Accumulator variables: curr, i, req
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int getKthElement ( int n , int k , int [ ] L , int [ ] R ) { int l = 1 ; int h = n ; int [ ] total = new int [ n + 1 ] ; total [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { total [ i + 1 ] = total [ i ] + ( R [ i ] - L [ i ] ) + 1 ; } int index = - 1 ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( total [ m ] > k ) { index = m ; h = m - 1 ; } else if ( total [ m ] < k ) l = m + 1 ; else { index = m ; break ; } } l = L [ index - 1 ] ; h = R [ index - 1 ] ; int x = k - total [ index - 1 ] ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( ( m - L [ index - 1 ] ) + 1 == x ) { return m ; } else if ( ( m - L [ index - 1 ] ) + 1 > x ) h = m - 1 ; else l = m + 1 ; } return k ; } public static void Main ( ) { int [ ] L = { 1 , 8 , 21 } ; int [ ] R = { 4 , 10 , 23 } ; int n = L . Length ; int k = 6 ; Console . WriteLine ( getKthElement ( n , k , L , R ) ) ; } }

Index/key variables: i, m
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
C# program:
using System ; class GFG { static int MinimumX ( int a , int b , int c , int k ) { int x = int . MaxValue ; if ( k <= c ) return 0 ; int h = k - c ; int l = 0 ; while ( l <= h ) { int m = ( l + h ) / 2 ; if ( ( a * m * m ) + ( b * m ) > ( k - c ) ) { x = Math . Min ( x , m ) ; h = m - 1 ; } else if ( ( a * m * m ) + ( b * m ) < ( k - c ) ) l = m + 1 ; else return m ; } return x ; } public static void Main ( ) { int a = 3 , b = 2 , c = 4 , k = 15 ; Console . Write ( MinimumX ( a , b , c , k ) ) ; } }

Class/struct names: GFG