codeparrot/xlcost-text-to-code huggingface dataset:
Find all possible binary trees with given Inorder Traversal | C # program to find binary tree with given inorder traversal ; Class containing left and right child of current node and key value ; Class to print Level Order Traversal ; A utility function to do preorder traversal of BST ; Function for constructing all possible trees with given inorder traversal stored in an array from arr [ start ] to arr [ end ] . This function returns a vector of trees . ; List to store all possible trees ; if start > end then subtree will be empty so returning NULL in the list ; Iterating through all values from start to end for constructing left and right subtree recursively ; Constructing left subtree ; Constructing right subtree ; Now looping through all left and right subtrees and connecting them to ith root below ; Making arr [ i ] as root ; Connecting left subtree ; Connecting right subtree ; Adding this tree to list ; Driver Code
using System ; using System . Collections . Generic ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = null ; right = null ; } } class GFG { public Node root ; public virtual void preOrder ( Node node ) { if ( node != null ) { Console . Write ( node . data + " ▁ " ) ; preOrder ( node . left ) ; preOrder ( node . right ) ; } } public virtual List < Node > getTrees ( int [ ] arr , int start , int end ) { List < Node > trees = new List < Node > ( ) ; if ( start > end ) { trees . Add ( null ) ; return trees ; } for ( int i = start ; i <= end ; i ++ ) { List < Node > ltrees = getTrees ( arr , start , i - 1 ) ; List < Node > rtrees = getTrees ( arr , i + 1 , end ) ; for ( int j = 0 ; j < ltrees . Count ; j ++ ) { for ( int k = 0 ; k < rtrees . Count ; k ++ ) { Node node = new Node ( arr [ i ] ) ; node . left = ltrees [ j ] ; node . right = rtrees [ k ] ; trees . Add ( node ) ; } } } return trees ; } public static void Main ( string [ ] args ) { int [ ] arr = new int [ ] { 4 , 5 , 7 } ; int n = arr . Length ; GFG tree = new GFG ( ) ; List < Node > trees = tree . getTrees ( arr , 0 , n - 1 ) ; Console . WriteLine ( " Preorder ▁ traversal ▁ of ▁ different ▁ " + " ▁ binary ▁ trees ▁ are : " ) ; for ( int i = 0 ; i < trees . Count ; i ++ ) { tree . preOrder ( trees [ i ] ) ; Console . WriteLine ( " " ) ; } } }
Check if a string is suffix of another | C # program to find if a string is suffix of another ; Test case - sensitive implementation of endsWith function
using System ; class GFG { public static void Main ( String [ ] args ) { String s1 = " geeks " , s2 = " geeksforgeeks " ; bool result = s2 . EndsWith ( s1 ) ; if ( result ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Maximum elements that can be made equal with k updates | C # program to find maximum elements that can be made equal with k updates ; Function to calculate the maximum number of equal elements possible with atmost K increment of values . Here we have done sliding window to determine that whether there are x number of elements present which on increment will become equal . The loop here will run in fashion like 0. . . x - 1 , 1. . . x , 2. . . x + 1 , ... . , n - x - 1. . . n - 1 ; It can be explained with the reasoning that if for some x number of elements we can update the values then the increment to the segment ( i to j having length -> x ) so that all will be equal is ( x * maxx [ j ] ) this is the total sum of segment and ( pre [ j ] - pre [ i ] ) is present sum So difference of them should be less than k if yes , then that segment length ( x ) can be possible return true ; sort the array in ascending order ; Initializing the prefix array and maximum array ; Calculating prefix sum of the array ; Calculating max value upto that position in the array ; Binary search applied for computation here ; printing result ; Driver code
using System ; class GFG { static bool ElementsCalculationFunc ( int [ ] pre , int [ ] maxx , int x , int k , int n ) { for ( int i = 0 , j = x ; j <= n ; j ++ , i ++ ) { if ( x * maxx [ j ] - ( pre [ j ] - pre [ i ] ) <= k ) return true ; } return false ; } static void MaxNumberOfElements ( int [ ] a , int n , int k ) { Array . Sort ( a ) ; for ( int i = 0 ; i <= n ; ++ i ) { pre [ i ] = 0 ; maxx [ i ] = 0 ; } for ( int i = 1 ; i <= n ; i ++ ) { pre [ i ] = pre [ i - 1 ] + a [ i - 1 ] ; maxx [ i ] = Math . Max ( maxx [ i - 1 ] , a [ i - 1 ] ) ; } int l = 1 , r = n , ans = 0 ; while ( l < r ) { int mid = ( l + r ) / 2 ; if ( ElementsCalculationFunc ( pre , maxx , mid - 1 , k , n ) ) { ans = mid ; l = mid + 1 ; } else r = mid - 1 ; } Console . Write ( ( int ) ans + " STRNEWLINE " ) ; } public static void Main ( ) { int [ ] arr = { 2 , 4 , 9 } ; int n = arr . Length ; int k = 3 ; MaxNumberOfElements ( arr , n , k ) ; } }
Count palindromic characteristics of a String | C # program which counts different palindromic characteristics of a string . ; function which checks whether a substring str [ i . . j ] of a given string is a palindrome or not . ; P [ i , j ] = true if substring str [ i . . j ] is palindrome , else false ; palindrome of single length ; palindrome of length 2 ; Palindromes of length more then 2. This loop is similar to Matrix Chain Multiplication . We start with a gap of length 2 and fill P table in a way that gap between starting and ending indexes increases one by one by outer loop . ; Pick starting point for current gap ; Set ending point ; If current string is palindrome ; function which recursively counts if a string str [ i . . j ] is a k - palindromic string or not . ; terminating condition for a string which is a k - palindrome . ; terminating condition for a string which is not a k - palindrome . ; increases the counter for the string if it is a k - palindrome . ; mid is middle pointer of the string str [ i ... j ] . ; if length of string which is ( j - i + 1 ) is odd than we have to subtract one from mid . else if even then no change . ; if the string is k - palindrome then we check if it is a ( k + 1 ) - palindrome or not by just sending any of one half of the string to the Count_k_Palindrome function . ; Finding all palindromic substrings of given string ; counting k - palindromes for each and every substring of given string . . ; Output the number of K - palindromic substrings of a given string . ; Driver code
using System ; class GFG { static int MAX_STR_LEN = 1000 ; static bool [ , ] P = new bool [ MAX_STR_LEN , MAX_STR_LEN ] ; static int [ ] Kpal = new int [ MAX_STR_LEN ] ; static void checkSubStrPal ( string str , int n ) { for ( int i = 0 ; i < MAX_STR_LEN ; i ++ ) { for ( int j = 0 ; j < MAX_STR_LEN ; j ++ ) P [ i , j ] = false ; Kpal [ i ] = 0 ; } for ( int i = 0 ; i < n ; i ++ ) P [ i , i ] = true ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( str [ i ] == str [ i + 1 ] ) P [ i , i + 1 ] = true ; for ( int gap = 2 ; gap < n ; gap ++ ) { for ( int i = 0 ; i < n - gap ; i ++ ) { int j = gap + i ; if ( str [ i ] == str [ j ] && P [ i + 1 , j - 1 ] ) P [ i , j ] = true ; } } } static void countKPalindromes ( int i , int j , int k ) { if ( i == j ) { Kpal [ k ] ++ ; return ; } if ( P [ i , j ] == false ) return ; Kpal [ k ] ++ ; int mid = ( i + j ) / 2 ; if ( ( j - i + 1 ) % 2 == 1 ) mid -- ; countKPalindromes ( i , mid , k + 1 ) ; } static void printKPalindromes ( string s ) { int n = s . Length ; checkSubStrPal ( s , n ) ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < n - i ; j ++ ) countKPalindromes ( j , j + i , 1 ) ; for ( int i = 1 ; i <= n ; i ++ ) Console . Write ( Kpal [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } static void Main ( ) { string s = " abacaba " ; printKPalindromes ( s ) ; } }
Print number in ascending order which contains 1 , 2 and 3 in their digits . | C # program to print all number containing 1 , 2 and 3 in any order . ; prints all the number containing 1 , 2 , 3 in any order ; check if the number contains 1 , 2 & 3 in any order ; sort all the numbers ; convert the number to string and find if it contains 1 , 2 & 3. ; Driver Code
using System ; using System . Collections . Generic ; using System . Text ; class GFG { private static string printNumbers ( int [ ] numbers ) { List < int > array = new List < int > ( ) ; foreach ( int number in numbers ) { if ( findContainsOneTwoThree ( number ) ) { array . Add ( number ) ; } } array . Sort ( ) ; StringBuilder strbuf = new StringBuilder ( ) ; System . Collections . IEnumerator it = array . GetEnumerator ( ) ; while ( it . MoveNext ( ) ) { int value = ( int ) it . Current ; if ( strbuf . Length > 0 ) { strbuf . Append ( " , ▁ " ) ; } strbuf . Append ( Convert . ToString ( value ) ) ; } return ( strbuf . Length > 0 ) ? strbuf . ToString ( ) : " - 1" ; } private static bool findContainsOneTwoThree ( int number ) { string str = Convert . ToString ( number ) ; return ( str . Contains ( "1" ) && str . Contains ( "2" ) && str . Contains ( "3" ) ) ; } public static void Main ( string [ ] args ) { int [ ] numbers = new int [ ] { 123 , 1232 , 456 , 234 , 32145 } ; Console . WriteLine ( printNumbers ( numbers ) ) ; } }
Find k | C # implementation to solve k queries for given n ranges ; Structure to store the start and end point ; Function to find Kth smallest number in a Vector of merged intervals ; Traverse merged . get ( ) o find Kth smallest element using Linear search . ; To combined both type of ranges , overlapping as well as non - overlapping . ; Sorting intervals according to start time ; Merging all intervals into merged ; To check if starting point of next range is lying between the previous range and ending point of next range is greater than the Ending point of previous range then update ending point of previous range by ending point of next range . ; If starting point of next range is greater than the ending point of previous range then store next range in merged . get ( . ) if ( curr . s > prev . e ) ; Driver code ; Merge all intervals into merged . get ( ) ) ; Processing all queries on merged intervals
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { public class Interval { public int s ; public int e ; public Interval ( int a , int b ) { s = a ; e = b ; } } ; class sortHelper : IComparer { int IComparer . Compare ( object a , object b ) { Interval first = ( Interval ) a ; Interval second = ( Interval ) b ; return first . s - second . s ; } } static int kthSmallestNum ( ArrayList merged , int k ) { int n = merged . Count ; for ( int j = 0 ; j < n ; j ++ ) { if ( k <= Math . Abs ( ( ( Interval ) merged [ j ] ) . e - ( ( Interval ) merged [ j ] ) . s + 1 ) ) return ( ( ( Interval ) merged [ j ] ) . s + k - 1 ) ; k = k - Math . Abs ( ( ( Interval ) merged [ j ] ) . e - ( ( Interval ) merged [ j ] ) . s + 1 ) ; } if ( k != 0 ) return - 1 ; return 0 ; } static ArrayList mergeIntervals ( ArrayList merged , Interval [ ] arr , int n ) { Array . Sort ( arr , new sortHelper ( ) ) ; merged . Add ( ( Interval ) arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { Interval prev = ( Interval ) merged [ merged . Count - 1 ] ; Interval curr = arr [ i ] ; if ( ( curr . s >= prev . s && curr . s <= prev . e ) && ( curr . e > prev . e ) ) { ( ( Interval ) merged [ merged . Count - 1 ] ) . e = ( ( Interval ) curr ) . e ; } else { merged . Add ( curr ) ; } } return merged ; } public static void Main ( string [ ] args ) { Interval [ ] arr = { new Interval ( 2 , 6 ) , new Interval ( 4 , 7 ) } ; int n = arr . Length ; int [ ] query = { 5 , 8 } ; int q = query . Length ; ArrayList merged = new ArrayList ( ) ; merged = mergeIntervals ( merged , arr , n ) ; for ( int i = 0 ; i < q ; i ++ ) Console . WriteLine ( kthSmallestNum ( merged , query [ i ] ) ) ; } }
Grouping Countries | C # program to count no . of distinct countries from a given group of people ; Answer is valid if adjacent sitting num people give same answer ; someone gives different answer ; check next person ; one valid country group has been found ; Driver Code
using System ; class Country { public static void countCountries ( int [ ] ans , int N ) { int total_countries = 0 , i = 0 ; while ( i < N ) { int curr_size = ans [ i ] ; int num = ans [ i ] ; while ( num > 0 ) { if ( ans [ i ] != curr_size ) { Console . Write ( " Invalid ▁ Answer STRNEWLINE " ) ; return ; } else num -- ; i ++ ; } total_countries ++ ; } Console . Write ( " There ▁ are ▁ " + total_countries + " ▁ distinct ▁ companies ▁ in ▁ the ▁ group . STRNEWLINE " ) ; } public static void Main ( ) { int [ ] ans = { 1 , 1 , 2 , 2 , 4 , 4 , 4 , 4 } ; int n = 8 ; countCountries ( ans , n ) ; } }
Deepest left leaf node in a binary tree | A C # program to find the deepest left leaf in a binary tree ; A Binary Tree node ; Constructor ; Class to evaluate pass by reference ; maxlevel : gives the value of level of maximum left leaf ; Node to store resultant node after left traversal ; A utility function to find deepest leaf node . lvl : level of current node . isLeft : A bool indicate that this node is left child ; Base case ; Update result if this node is left leaf and its level is more than the maxl level of the current result ; Recur for left and right subtrees ; A wrapper over deepestLeftLeafUtil ( ) . ; Driver program to test above functions
using System ; public class Node { public int data ; public Node left , right ; public Node ( int data ) { this . data = data ; left = right = null ; } } public class Level { public int maxlevel = 0 ; } public class BinaryTree { public Node root ; public Node result ; public virtual void deepestLeftLeafUtil ( Node node , int lvl , Level level , bool isLeft ) { if ( node == null ) { return ; } if ( isLeft != false && node . left == null && node . right == null && lvl > level . maxlevel ) { result = node ; level . maxlevel = lvl ; } deepestLeftLeafUtil ( node . left , lvl + 1 , level , true ) ; deepestLeftLeafUtil ( node . right , lvl + 1 , level , false ) ; } public virtual void deepestLeftLeaf ( Node node ) { Level level = new Level ( ) ; deepestLeftLeafUtil ( node , 0 , level , false ) ; } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . right . left = new Node ( 5 ) ; tree . root . right . right = new Node ( 6 ) ; tree . root . right . left . right = new Node ( 7 ) ; tree . root . right . right . right = new Node ( 8 ) ; tree . root . right . left . right . left = new Node ( 9 ) ; tree . root . right . right . right . right = new Node ( 10 ) ; tree . deepestLeftLeaf ( tree . root ) ; if ( tree . result != null ) { Console . WriteLine ( " The ▁ deepest ▁ left ▁ child ▁ is ▁ " + tree . result . data ) ; } else { Console . WriteLine ( " There ▁ is ▁ no ▁ left ▁ leaf ▁ in ▁ the ▁ given ▁ tree " ) ; } } }
Check if an array contains all elements of a given range | C # Code for Check if an array contains all elements of a given range ; Function to check the array for elements in given range ; Range is the no . of elements that are to be checked ; Traversing the array ; If an element is in range ; Checking whether elements in range 0 - range are negative ; Element from range is missing from array ; All range elements are present ; Driver Code ; Defining Array and size ; A is lower limit and B is the upper limit of range ; True denotes all elements were present ; False denotes any element was not present
using System ; class GFG { public static bool check_elements ( int [ ] arr , int n , int A , int B ) { int range = B - A ; for ( int i = 0 ; i < n ; i ++ ) { if ( Math . Abs ( arr [ i ] ) >= A && Math . Abs ( arr [ i ] ) <= B ) { int z = Math . Abs ( arr [ i ] ) - A ; if ( arr [ z ] > 0 ) { arr [ z ] = arr [ z ] * - 1 ; } } } int count = 0 ; for ( int i = 0 ; i <= range && i < n ; i ++ ) { if ( arr [ i ] > 0 ) return false ; else count ++ ; } if ( count != ( range + 1 ) ) return false ; return true ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 4 , 5 , 2 , 7 , 8 , 3 } ; int n = arr . Length ; int A = 2 , B = 5 ; if ( check_elements ( arr , n , A , B ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Recursive Programs to find Minimum and Maximum elements of array | Recursive C # program to find minimum ; function to return minimum element using recursion ; if size = 0 means whole array has been traversed ; Driver code
using System ; class GFG { public static int findMinRec ( int [ ] A , int n ) { if ( n == 1 ) return A [ 0 ] ; return Math . Min ( A [ n - 1 ] , findMinRec ( A , n - 1 ) ) ; } static public void Main ( ) { int [ ] A = { 1 , 4 , 45 , 6 , - 50 , 10 , 2 } ; int n = A . Length ; Console . WriteLine ( findMinRec ( A , n ) ) ; } }
Allocate minimum number of pages | C # program for optimal allocation of pages ; Utility function to check if current minimum value is feasible or not . ; iterate over all books ; check if current number of pages are greater than curr_min that means we will get the result after mid no . of pages ; count how many students are required to distribute curr_min pages ; increment student count ; update curr_sum ; if students required becomes greater than given no . of students , return false ; else update curr_sum ; function to find minimum pages ; return - 1 if no . of books is less than no . of students ; Count total number of pages ; initialize start as 0 pages and end as total pages ; traverse until start <= end ; check if it is possible to distribute books by using mid as current minimum ; update result to current distribution as it 's the best we have found till now. ; as we are finding minimum and books are sorted so reduce end = mid - 1 that means ; if not possible means pages should be increased so update start = mid + 1 ; at - last return minimum no . of pages ; Drivers code ; Number of pages in books ; int m = 2 ; No . of students
using System ; class GFG { static bool isPossible ( int [ ] arr , int n , int m , int curr_min ) { int studentsRequired = 1 ; int curr_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > curr_min ) return false ; if ( curr_sum + arr [ i ] > curr_min ) { studentsRequired ++ ; curr_sum = arr [ i ] ; if ( studentsRequired > m ) return false ; } else curr_sum += arr [ i ] ; } return true ; } static int findPages ( int [ ] arr , int n , int m ) { long sum = 0 ; if ( n < m ) return - 1 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; int start = 0 , end = ( int ) sum ; int result = int . MaxValue ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( isPossible ( arr , n , m , mid ) ) { result = mid ; end = mid - 1 ; } else start = mid + 1 ; } return result ; } static public void Main ( ) { int [ ] arr = { 12 , 34 , 67 , 90 } ; int n = arr . Length ; Console . WriteLine ( " Minimum ▁ number ▁ of ▁ pages ▁ = ▁ " + findPages ( arr , n , m ) ) ; } }
Find Minimum Depth of a Binary Tree | C # implementation to find minimum depth of a given Binary tree ; Class containing left and right child of current node and key value ; Root of the Binary Tree ; Function to calculate the minimum depth of the tree ; Corner case . Should never be hit unless the code is called on root = NULL ; Base case : Leaf Node . This accounts for height = 1. ; If left subtree is NULL , recur for right subtree ; If right subtree is NULL , recur for left subtree ; Driver program to test above functions ; Let us construct the Tree shown in the above figure
using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { public Node root ; public virtual int minimumDepth ( ) { return minimumDepth ( root ) ; } public virtual int minimumDepth ( Node root ) { if ( root == null ) { return 0 ; } if ( root . left == null && root . right == null ) { return 1 ; } if ( root . left == null ) { return minimumDepth ( root . right ) + 1 ; } if ( root . right == null ) { return minimumDepth ( root . left ) + 1 ; } return Math . Min ( minimumDepth ( root . left ) , minimumDepth ( root . right ) ) + 1 ; } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; Console . WriteLine ( " The ▁ minimum ▁ depth ▁ of ▁ binary ▁ tree ▁ is ▁ : ▁ " + tree . minimumDepth ( ) ) ; } }
Remove an occurrence of most frequent array element exactly K times | C # program for the above approach ; Function to print the most frequent array element exactly K times ; Stores frequency array element ; Count frequency of array element ; Maximum array element ; Traverse the Map ; Find the element with maximum frequency ; If the frequency is maximum , store that number in element ; Print element as it contains the element having highest frequency ; Decrease the frequency of the maximum array element ; Reduce the number of operations ; Driver Code ; Given array ; Size of the array ; Given K
using System ; using System . Collections . Generic ; class GFG { static void maxFreqElements ( int [ ] arr , int N , int K ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] ++ ; } else { mp [ arr [ i ] ] = 1 ; } } while ( K > 0 ) { int max = 0 ; int element = 0 ; foreach ( KeyValuePair < int , int > i in mp ) { if ( i . Value > max ) { max = i . Value ; element = i . Key ; } } Console . Write ( element + " ▁ " ) ; if ( mp . ContainsKey ( element ) ) { mp [ element ] -- ; } else { mp [ element ] = - 1 ; } K -- ; } } static void Main ( ) { int [ ] arr = { 1 , 3 , 2 , 1 , 4 , 1 } ; int N = arr . Length ; int K = 2 ; maxFreqElements ( arr , N , K ) ; } }
Maximize difference between maximum and minimum array elements after K operations | C # program to implement the above approach ; Function to find the maximum difference between the maximum and minimum in the array after K operations ; Stores maximum difference between largest and smallest array element ; Sort the array in descending order ; Traverse the array arr [ ] ; Update maxDiff ; Driver code
using System ; class GFG { static int maxDiffLargSmallOper ( int [ ] arr , int N , int K ) { int maxDiff = 0 ; Array . Sort ( arr ) ; Array . Reverse ( arr ) ; for ( int i = 0 ; i <= Math . Min ( K , N - 1 ) ; i ++ ) { maxDiff += arr [ i ] ; } return maxDiff ; } public static void Main ( ) { int [ ] arr = new int [ ] { 7 , 7 , 7 , 7 } ; int N = arr . Length ; int K = 1 ; Console . Write ( maxDiffLargSmallOper ( arr , N , K ) ) ; } }
Minimize cost to convert all characters of a binary string to 0 s | C # program to implement the above approach ; Function to get the minimum Cost to convert all characters of given string to 0 s ; Stores the range of indexes of characters that need to be flipped ; Stores the number of times current character is flipped ; Stores minimum cost to get the required string ; Traverse the given string ; Remove all value from pq whose value is less than i ; Update flip ; Get the current number ; If current character is flipped odd times ; If current character contains non - zero value ; Update flip ; Update cost ; Append R [ i ] into pq ; Driver Code ; Function call
using System ; using System . Collections . Generic ; class GFG { public static int minCost ( String s , int [ ] R , int [ ] C , int N ) { char [ ] ch = s . ToCharArray ( ) ; Queue < int > pq = new Queue < int > ( ) ; int flip = 0 ; int cost = 0 ; for ( int i = 0 ; i < N ; i ++ ) { while ( pq . Count > 0 && pq . Peek ( ) < i ) { pq . Dequeue ( ) ; flip -- ; } int cn = ch [ i ] - '0' ; if ( flip % 2 == 1 ) cn = 1 - cn ; if ( cn == 1 ) { flip ++ ; cost += C [ i ] ; pq . Enqueue ( R [ i ] ) ; } } return cost ; } public static void Main ( String [ ] args ) { int N = 4 ; String s = "1010" ; int [ ] R = { 1 , 2 , 2 , 3 } ; int [ ] C = { 3 , 1 , 2 , 3 } ; Console . WriteLine ( minCost ( s , R , C , N ) ) ; } }