codeparrot/xlcost-text-to-code huggingface dataset:
Maximize Kth largest element after splitting the given Array at most C times | C # program for the above approach ; Function to find the K - th maximum element after upto C operations ; Check for the base case ; Stores the count iterations of BS ; Create the left and right bounds of binary search ; Perform binary search ; Find the value of mid ; Traverse the array ; Update the ranges ; Return the maximum value obtained ; Driver Code
using System ; class GFG { static double maxKth ( int [ ] arr , int N , int C , int K ) { if ( N + C < K ) { return - 1 ; } int iter = 300 ; double l = 0 , r = 1000000000.0 ; while ( iter -- > 0 ) { double mid = ( l + r ) * 0.5 ; double a = 0 ; double b = 0 ; for ( int i = 0 ; i < N ; i ++ ) { a += ( int ) ( ( double ) arr [ i ] / mid ) ; if ( ( double ) arr [ i ] >= mid ) { b ++ ; } } if ( a >= K && b + C >= K ) { l = mid ; } else { r = mid ; } } return l ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 8 } ; int K = 1 , C = 1 ; int N = arr . Length ; Console . Write ( maxKth ( arr , N , C , K ) ) ; } }
Maximize the minimum difference between any element pair by selecting K elements from given Array | C # implementation for the above approach ; To check if selection of K elements is possible such that difference between them is greater than dif ; Selecting first element in the sorted array ; prev is the previously selected element initially at index 0 as first element is already selected ; Check if selection of K - 1 elements from array with a minimum difference of dif is possible ; If the current element is atleast dif difference apart from the previously selected element then select the current element and increase the count ; If selection of K elements with a min difference of dif is possible then return true ; Prev will become current element for the next iteration ; If selection of K elements with minimum difference of dif is not possible then return false ; Minimum largest difference possible is 1 ; Check if selection of K elements is possible with a minimum difference of dif ; If dif is greater than previous ans we update ans ; Continue to search for better answer . Try finding greater dif ; K elements cannot be selected ; Driver code ; arr should be in a sorted order
using System ; using System . Collections . Generic ; class GFG { static bool isPossibleToSelect ( int [ ] arr , int N , int dif , int K ) { int count = 1 ; int prev = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] >= ( prev + dif ) ) { count ++ ; if ( count == K ) return true ; prev = arr [ i ] ; } } return false ; } static int binarySearch ( int [ ] arr , int left , int right , int K , int N ) { int ans = 1 ; while ( left <= right ) { int dif = left + ( right - left ) / 2 ; if ( isPossibleToSelect ( arr , N , dif , K ) ) { ans = Math . Max ( ans , dif ) ; left = dif + 1 ; } else right = dif - 1 ; } return ans ; } public static void Main ( ) { int N , K ; N = 7 ; K = 4 ; int [ ] arr = { 1 , 4 , 9 , 0 , 2 , 13 , 3 } ; Array . Sort ( arr ) ; Console . Write ( binarySearch ( arr , 0 , arr [ N - 1 ] , K , N ) ) ; } }
Find maximum height to cut all chocolates horizontally such that at least K amount remains | C # program for the above approach ; Function to find the sum of remaining chocolate after making the horizontal cut at height mid ; Stores the sum of chocolates ; Traverse the array arr [ ] ; If the height is at least mid ; Return the possible sum ; Function to find the maximum horizontal cut made to all the chocolates such that the sum of the remaining element is at least K ; Ranges of Binary Search ; Perform the Binary Search ; Find the sum of removed after making cut at height mid ; If the chocolate removed is same as the chocolate needed then return the height ; If the chocolate removed is less than chocolate needed then shift to the left range ; Otherwise , shift to the right range ; Return the possible cut ; Driver Code
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static int cal ( List < int > arr , int mid ) { int chocolate = 0 ; foreach ( int i in arr ) { if ( i >= mid ) chocolate += i - mid ; } return chocolate ; } static int maximumCut ( List < int > arr , int K ) { int low = 0 ; int high = arr . Max ( ) ; while ( low <= high ) { int mid = ( low + high ) / 2 ; int chocolate = cal ( arr , mid ) ; if ( chocolate == K ) return mid ; else if ( chocolate < K ) high = mid - 1 ; else { low = mid + 1 ; if ( mid > high ) high = mid ; } } return high ; } public static void Main ( ) { int K = 7 ; List < int > arr = new List < int > ( ) { 15 , 20 , 8 , 17 } ; Console . Write ( maximumCut ( arr , K ) ) ; } }
Koko Eating Bananas | C # implementation for the above approach ; to get the ceil value ; in case of odd number ; in case of even number ; check if time is less than or equals to given hour ; as minimum speed of eating must be 1 ; Maximum speed of eating is the maximum bananas in given piles ; Check if the mid ( hours ) is valid ; If valid continue to search lower speed ; If cant finish bananas in given hours , then increase the speed ; Driver code
using System ; using System . Linq ; public class GFG { static bool check ( int [ ] bananas , int mid_val , int H ) { int time = 0 ; for ( int i = 0 ; i < bananas . Length ; i ++ ) { if ( bananas [ i ] % mid_val != 0 ) { time += ( ( bananas [ i ] / mid_val ) + 1 ) ; } else { time += ( bananas [ i ] / mid_val ) ; } } if ( time <= H ) { return true ; } else { return false ; } } static int minEatingSpeed ( int [ ] piles , int H ) { int start = 1 ; int end = piles . Max ( ) ; while ( start < end ) { int mid = start + ( end - start ) / 2 ; if ( ( check ( piles , mid , H ) ) == true ) { end = mid ; } else { start = mid + 1 ; } } return end ; } public static void Main ( String [ ] args ) { int [ ] piles = { 30 , 11 , 23 , 4 , 20 } ; int H = 6 ; Console . Write ( minEatingSpeed ( piles , H ) ) ; } }
Minimize the sum of pair which upon removing divides the Array into 3 subarrays | C # implementation of the above approach ; Function to find minimum possible sum of pair which breaks the array into 3 non - empty subarrays ; prefixMin [ i ] contains minimum element till i ; Driver Code ; Given array
using System ; public class GFG { static int minSumPair ( int [ ] arr , int N ) { if ( N < 5 ) { return - 1 ; } int [ ] prefixMin = new int [ N ] ; prefixMin [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N - 1 ; i ++ ) { prefixMin [ i ] = Math . Min ( arr [ i ] , prefixMin [ i - 1 ] ) ; } int ans = int . MaxValue ; for ( int i = 3 ; i < N - 1 ; i ++ ) { ans = Math . Min ( ans , arr [ i ] + prefixMin [ i - 2 ] ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 2 , 4 , 6 , 3 , 7 } ; int N = arr . Length ; Console . Write ( minSumPair ( arr , N ) + " STRNEWLINE " ) ; } }
Minimum time remaining for safety alarm to start | C # program for the above approach ; Function to check if the value of mid as the minimum number of hours satisfies the condition ; Stores the sum of speed ; Iterate over the range [ 0 , N ] ; Find the value of speed ; If the bike is considered to be fast add it in sum ; Return the resultant sum ; Function to find the minimum number of time required ; Stores the range of Binary Search ; Stores the minimum number of time required ; Find the value of mid ; If the mid is the resultant speed required ; Update the ans and high ; Otherwise ; Return the minimum number of hours ; Driver Code
using System ; class GFG { static long check ( long [ ] H , long [ ] A , long mid , long N , long M , long L ) { long sum = 0 ; for ( long i = 0 ; i < N ; i ++ ) { long speed = mid * A [ ( int ) i ] + H [ ( int ) i ] ; if ( speed >= L ) { sum += speed ; } } return sum ; } static long buzzTime ( long N , long M , long L , long [ ] H , long [ ] A ) { long low = 0 , high = 100000000 ; long ans = 0 ; while ( high >= low ) { long mid = low + ( high - low ) / 2 ; if ( check ( H , A , mid , N , M , L ) >= M ) { ans = mid ; high = mid - 1 ; } else low = mid + 1 ; } return ans ; } public static void Main ( String [ ] args ) { long M = 400 , L = 120 ; long [ ] H = { 20 , 50 , 20 } ; long [ ] A = { 20 , 70 , 90 } ; long N = A . Length ; Console . Write ( buzzTime ( N , M , L , H , A ) ) ; } }
Count of different numbers divisible by 3 that can be obtained by changing at most one digit | C # program fo the above approach ; Function to count the number of possible numbers divisible by 3 ; Calculate the sum ; Store the answer ; Iterate over the range ; Decreasing the sum ; Iterate over the range ; Checking if the new sum is divisible by 3 or not ; If yes increment the value of the count ; Driver Code ; Given number
using System ; using System . Collections . Generic ; class GFG { static void findCount ( string number ) { int sum = 0 ; for ( int i = 0 ; i < number . Length ; ++ i ) { sum += ( int ) number [ i ] - 48 ; } int count = 0 ; for ( int i = 0 ; i < number . Length ; ++ i ) { int remaining_sum = sum - ( ( int ) number [ i ] - 48 ) ; for ( int j = 0 ; j <= 9 ; ++ j ) { if ( ( remaining_sum + j ) % 3 == 0 && j != number [ i ] - 48 ) { ++ count ; } } } Console . Write ( count ) ; } public static void Main ( ) { string number = "235" ; findCount ( number ) ; } }
Maximum number of teams of size K possible with each player from different country | C # program for the above approach ; Function to find if T number of teams can be formed or not ; Store the sum of array elements ; Traverse the array teams [ ] ; Required Condition ; Function to find the maximum number of teams possible ; Lower and Upper part of the range ; Perform the Binary Search ; Find the value of mid ; Perform the Binary Search ; Otherwise , update the search range ; Otherwise , update the search range ; Driver Code
using System ; class GFG { public static bool is_possible ( int [ ] teams , int T , int k ) { int sum = 0 ; for ( int i = 0 ; i < teams . Length ; i ++ ) { sum += Math . Min ( T , teams [ i ] ) ; } return ( sum >= ( T * k ) ) ; } public static int countOfTeams ( int [ ] teams_list , int N , int K ) { int lb = 0 ; double ub = 1e9 ; while ( lb <= ub ) { int mid = lb + ( int ) ( ub - lb ) / 2 ; if ( is_possible ( teams_list , mid , K ) ) { if ( ! is_possible ( teams_list , mid + 1 , K ) ) { return mid ; } else { lb = mid + 1 ; } } else { ub = mid - 1 ; } } return 0 ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 4 } ; int K = 2 ; int N = arr . Length ; Console . WriteLine ( countOfTeams ( arr , N , K ) ) ; } }
Minimum number of decrements by 1 required to reduce all elements of a circular array to 0 | C # program for the above approach ; Function to find minimum operation require to make all elements 0 ; Stores the maximum element and its position in the array ; Traverse the array ; Update the maximum element and its index ; Print the minimum number of operations required ; Driver Code
using System ; class GFG { static void minimumOperations ( int [ ] arr , int N ) { int mx = 0 , pos = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= mx ) { mx = arr [ i ] ; pos = i ; } } Console . Write ( ( mx - 1 ) * N + pos + 1 ) ; } public static void Main ( ) { int [ ] arr = { 2 , 0 , 2 } ; int N = arr . Length ; minimumOperations ( arr , N ) ; } }
Maximize the smallest array element by incrementing all elements in a K | C # program for above approach ; Function to check if the smallest value of v is achievable or not ; Create array to store previous moves ; Remove previous moves ; Add balance to ans ; Update contiguous subarray of length k ; Number of moves should not exceed m ; Function to find the maximum value of the smallest array element that can be obtained ; Perform Binary search ; Driver Code ; Given Input ; Function Call
using System ; public class GFG { static long n , m , k , l , r , i ; static bool check ( long v , long [ ] a ) { long tec = 0 , ans = 0 ; long [ ] b = new long [ ( int ) ( n + k + 1 ) ] ; for ( int i = 0 ; i < n ; i ++ ) { tec -= b [ i ] ; if ( a [ i ] + tec < v ) { long mov = v - a [ i ] - tec ; ans = ans + mov ; tec += mov ; b [ i + ( int ) k ] = mov ; } } return ans <= m ; } static long FindLargest ( long [ ] a ) { l = 1 ; r = ( long ) Math . Pow ( 10 , 10 ) ; while ( r - l > 0 ) { long tm = ( l + r + 1 ) / 2 ; if ( check ( tm , a ) ) l = tm ; else r = tm - 1 ; } return l ; } public static void Main ( String [ ] args ) { long [ ] a = { 2 , 2 , 2 , 2 , 1 , 1 } ; m = 2 ; k = 3 ; n = a . Length ; Console . WriteLine ( FindLargest ( a ) ) ; } }
Find value K in given Complete Binary Tree with values indexed from 1 to N | C # program for the above approach ; Class containing left and right child of current node and key value ; Function to store the list of the directions ; While the root is not found ; If it is the right child of its parent ; Add right step ( 1 ) ; Add left step ( - 1 ) ; Repeat the same for its parent ; Reverse the steps list ; Return the steps ; Function to find if the key is present or not ; Get the steps to be followed ; Taking one step at a time ; Go left ; If left child does not exist return false ; Go right ; If right child does not exist return false ; If the entire array of steps has been successfully traversed ; Consider the following complete binary tree 1 / \ 2 3 / \ / \ 4 5 6 7 / \ / 8 9 10 ; Function Call
using System ; using System . Collections . Generic ; class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class Solution { public static List < int > findSteps ( Node root , int data ) { List < int > steps = new List < int > ( ) ; while ( data != 1 ) { if ( data / 2.0 > data / 2 ) { steps . Add ( 1 ) ; } else { steps . Add ( - 1 ) ; } int parent = data / 2 ; data = parent ; } steps . Reverse ( ) ; return steps ; } public static bool findKey ( Node root , int data ) { List < int > steps = findSteps ( root , data ) ; foreach ( int cur_step in steps ) { if ( cur_step == - 1 ) { if ( root . left == null ) return false ; root = root . left ; } else { if ( root . right == null ) return false ; root = root . right ; } } return true ; } public static void Main ( ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . left . right = new Node ( 5 ) ; root . right . left = new Node ( 6 ) ; root . right . right = new Node ( 7 ) ; root . left . left . left = new Node ( 8 ) ; root . left . left . right = new Node ( 9 ) ; root . left . right . left = new Node ( 10 ) ; Console . Write ( findKey ( root , 7 ) ) ; } }
Altitude of largest Triangle that can be inscribed in a Rectangle | C # program for the above approach ; Function to find the greatest altitude of the largest triangle triangle that can be inscribed in the rectangle ; If L is greater than B ; Variables to perform binary search ; Stores the maximum altitude possible ; Iterate until low is less than high ; Stores the mid value ; If mide is less than or equal to the B / 2 ; Update res ; Update low ; Update high ; Print the result ; Driver Code ; Given Input ; Function call
using System ; class GFG { static int largestAltitude ( int L , int B ) { if ( L > B ) { int t = L ; L = B ; B = t ; } int low = 0 , high = L ; int res = 0 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( mid <= ( B / 2 ) ) { res = mid ; low = mid + 1 ; } else high = mid - 1 ; } return res ; } public static void Main ( string [ ] args ) { int L = 3 ; int B = 4 ; Console . Write ( largestAltitude ( L , B ) ) ; } }
Find the frequency of each element in a sorted array | C # program for the above approach ; Function to print the frequency of each element of the sorted array ; Stores the frequency of an element ; Traverse the array arr [ ] ; If the current element is equal to the previous element ; Increment the freq by 1 ; Otherwise , ; Update freq ; Print the frequency of the last element ; Driver Code ; Given Input ; Function Call
using System ; public class GFG { static void printFreq ( int [ ] arr , int N ) { int freq = 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) { freq ++ ; } else { Console . WriteLine ( " Frequency ▁ of ▁ " + arr [ i - 1 ] + " ▁ is : ▁ " + freq ) ; freq = 1 ; } } Console . WriteLine ( " Frequency ▁ of ▁ " + arr [ N - 1 ] + " ▁ is : ▁ " + freq ) ; } static public void Main ( ) { int [ ] arr = { 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 } ; int N = arr . Length ; printFreq ( arr , N ) ; } }
Maximize median of a KxK sub | C # program for the above approach ; Function to determine if a given value can be median ; Stores the prefix sum array ; Traverse the matrix arr [ ] [ ] ; Update Pre [ i + 1 ] [ j + 1 ] ; If arr [ i ] [ j ] is less than or equal to mid ; Stores the count of elements should be less than mid ; Stores if the median mid can be possible or not ; Iterate over the range [ K , N ] ; Iterate over the range [ K , N ] ; Stores count of elements less than or equal to the value mid in submatrix with bottom right vertices at ( i , j ) ; If X is less than or equal to required ; Return flag ; Function to find the maximum median of a subsquare of the given size ; Stores the range of the search space ; Iterate until low is less than high ; Stores the mid value of the range [ low , high ] ; If the current median can be possible ; Update the value of low ; Update the value of high ; Return value stored in low as answer ; Driver code
using System ; class GFG { static bool isMaximumMedian ( int [ , ] arr , int N , int K , int mid ) { int [ , ] Pre = new int [ N + 5 , N + 5 ] ; for ( int i = 0 ; i < N ; ++ i ) { for ( int j = 0 ; j < N ; ++ j ) { Pre [ i + 1 , j + 1 ] = Pre [ i + 1 , j ] + Pre [ i , j + 1 ] - Pre [ i , j ] ; if ( arr [ i , j ] <= mid ) Pre [ i + 1 , j + 1 ] ++ ; } } int required = ( K * K + 1 ) / 2 ; bool flag = false ; for ( int i = K ; i <= N ; ++ i ) { for ( int j = K ; j <= N ; ++ j ) { int X = Pre [ i , j ] - Pre [ i - K , j ] - Pre [ i , j - K ] + Pre [ i - K , j - K ] ; if ( X < required ) flag = true ; } } return flag ; } static int maximumMedian ( int [ , ] arr , int N , int K ) { int low = 0 , high = ( int ) 1e9 ; while ( low < high ) { int mid = low + ( high - low ) / 2 ; if ( isMaximumMedian ( arr , N , K , mid ) ) { low = mid + 1 ; } else { high = mid ; } } return low ; } public static void Main ( string [ ] args ) { int [ , ] arr = { { 1 , 5 , 12 } , { 6 , 7 , 11 } , { 8 , 9 , 10 } } ; int N = arr . GetLength ( 0 ) ; int K = 2 ; Console . WriteLine ( maximumMedian ( arr , N , K ) ) ; } }
Minimum days to make Array elements with value at least K sum at least X | C # program for the above approach ; Function to find the minimum number of days such that the sum of array elements >= K is at least X ; Initialize the boundaries of search space ; Perform the binary search ; Find the value of mid ; Traverse the array , arr [ ] ; Find the value of arr [ i ] after mid number of days ; Check if temp is not less than K ; Update the value of sum ; Check if the value of sum is greater than X ; Update value of high ; Update the value of low ; Print the minimum number of days ; Driver Code
using System ; class GFG { static void findMinDays ( int [ ] arr , int [ ] R , int N , int X , int K ) { int low = 0 , high = X ; int minDays = - 1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int temp = arr [ i ] + R [ i ] * mid ; if ( temp >= K ) { sum += temp ; } } if ( sum >= X ) { minDays = mid ; high = mid - 1 ; } else { low = mid + 1 ; } } Console . Write ( minDays ) ; } public static void Main ( string [ ] args ) { int X = 100 , K = 45 ; int [ ] arr = { 2 , 5 , 2 , 6 } ; int [ ] R = { 10 , 13 , 15 , 12 } ; int N = arr . Length ; findMinDays ( arr , R , N , X , K ) ; } }
Count of indices pairs such that product of elements at these indices is equal to absolute difference of indices | C # program for the above approach ; Function to count the number of pairs ( i , j ) such that arr [ i ] * arr [ j ] is equal to abs ( i - j ) ; Stores the resultant number of pairs ; Generate all possible pairs from the array arr [ ] ; If the given condition satisfy then increment the value of count ; Return the resultant count ; Driver Code
using System ; class GFG { static int getPairsCount ( int [ ] a , int n ) { int count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( ( a [ i ] * a [ j ] ) == Math . Abs ( i - j ) ) count ++ ; } } return count ; } public static void Main ( ) { int [ ] arr = { 1 , 1 , 2 , 4 } ; int N = arr . Length ; Console . Write ( getPairsCount ( arr , N ) ) ; } }
Lexicographically smallest string formed repeatedly deleting character from substring 10 | C # program for the above approach ; Function to find smallest lexicogra - phically smallest string ; Stores the index of last occuring 0 ; Stores the lexicographically smallest string ; Traverse the string S ; If str [ i ] is 0 ; Assign i to lastZe ; Traverse the string str ; If i is less than or equal to lastZe and str [ i ] is 0 ; If i is greater than lastZe ; Return ans ; Driver Code ; Input ; Function Call
using System ; class GFG { static string lexicographicallySmallestString ( string S , int N ) { int LastZe = - 1 ; string ans = " " ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( S [ i ] == '0' ) { LastZe = i ; break ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( i <= LastZe && S [ i ] == '0' ) ans += S [ i ] ; else if ( i > LastZe ) ans += S [ i ] ; } return ans ; } public static void Main ( ) { string S = "11001101" ; int N = S . Length ; Console . Write ( lexicographicallySmallestString ( S , N ) ) ; } }
Maximize boxes required to keep at least one black and one white shirt | C # program for the above approach ; Function to find the maximum number of boxes such that each box contains three shirts comprising of at least one white and black shirt ; Stores the low and high pointers for binary search ; Store the required answer ; Loop while low <= high ; Store the mid value ; Check if the mid number of boxes can be used ; Update answer and recur for the right half ; Else , recur for the left half ; Print the result ; Driver Code
using System ; class GFG { static void numberofBoxes ( int W , int B , int O ) { int low = 0 , high = Math . Min ( W , B ) ; int ans = 0 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( ( ( W >= mid ) && ( B >= mid ) ) && ( ( W - mid ) + ( B - mid ) + O ) >= mid ) { ans = mid ; low = mid + 1 ; } else high = mid - 1 ; } Console . Write ( ans ) ; } public static void Main ( ) { int W = 3 , B = 3 , O = 1 ; numberofBoxes ( W , B , O ) ; } }
Minimum swaps needed to convert given Binary Matrix A to Binary Matrix B | C # program for the above approach ; Function to count the minimum number of swaps required to convert matrix A to matrix B ; Stores number of cells such that matrix A contains 0 and matrix B contains 1 ; Stores number of cells such that matrix A contains 1 and matrix B contains 0 ; Iterate over the range [ 0 , N - 1 ] ; Iterate over the range [ 0 , M - 1 ] ; If A [ i ] [ j ] = 1 and B [ i ] [ j ] = 0 ; If A [ i ] [ j ] = 0 and B [ i ] [ j ] = 1 ; If count01 is equal to count10 ; Otherwise , ; Driver code
using System ; class GFG { public static int minSwaps ( int N , int M , int [ , ] A , int [ , ] B ) { int count01 = 0 ; int count10 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( A [ i , j ] != B [ i , j ] ) { if ( A [ i , j ] == 1 ) count10 ++ ; else count01 ++ ; } } } if ( count01 == count10 ) return count01 ; else return - 1 ; } public static void Main ( String [ ] args ) { int [ , ] A = { { 1 , 1 , 0 } , { 0 , 0 , 1 } , { 0 , 1 , 0 } } ; int [ , ] B = { { 0 , 0 , 1 } , { 0 , 1 , 0 } , { 1 , 1 , 0 } } ; int N = A . GetLength ( 0 ) ; int M = 3 ; Console . Write ( minSwaps ( N , M , A , B ) ) ; } }