codeparrot/xlcost-text-to-code huggingface dataset:
Maximum Pairs of Bracket Sequences which can be concatenated to form a Regular Bracket Sequence | C # program for the above approach ; Function to count the number of pairs whose concatenation results in the regular bracket sequence ; Stores the count of opening and closing parenthesis for each string arr [ i ] ; Stores maximum count of pairs ; Traverse the array arr [ ] ; Traverse the string c [ ] ; Opening Bracket ; Otherwise , Closing Bracket ; Count of closing brackets needed to balance string ; Count of opening brackets needed to balance string ; Add the count of balanced sequences ; Traverse the array ; Print the resultant count ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void countPairs ( int N , List < string > arr ) { int [ ] open = new int [ 100 ] ; int [ ] close = new int [ 100 ] ; int ans = 0 ; for ( int i = 0 ; i < N ; i ++ ) { char [ ] c = arr [ i ] . ToCharArray ( ) ; int d = 0 ; int min = 0 ; for ( int j = 0 ; j < c . Length ; j ++ ) { if ( c [ j ] == ' ( ' ) { d ++ ; } else { d -- ; if ( d < min ) min = d ; } } if ( d >= 0 ) { if ( min == 0 ) close [ d ] ++ ; } else if ( d < 0 ) { if ( min == d ) open [ - d ] ++ ; } } ans += close [ 0 ] / 2 ; for ( int i = 1 ; i < 100 ; i ++ ) { ans += Math . Min ( open [ i ] , close [ i ] ) ; } Console . WriteLine ( ans ) ; } public static void Main ( string [ ] args ) { int N = 7 ; List < string > list = new List < string > ( ) ; list . Add ( " ) ( ) ) " ) ; list . Add ( " ) " ) ; list . Add ( " ( ( " ) ; list . Add ( " ( ( " ) ; list . Add ( " ( " ) ; list . Add ( " ) " ) ; list . Add ( " ) " ) ; countPairs ( N , list ) ; } }
Minimum count of elements to be inserted in Array to form all values in [ 1 , K ] using subset sum | C # program for the above approach ; Function to find the count of minimum elements to be inserted to form every number in a range ; Stores the count of numbers needed ; Stores the numbers upto which every numbers can be formed ; Stores the index of the array arr [ ] ; Iterate until requiredSum is less than or equal to K ; If i is less than N and requiredSum is greater than or equal to arr [ i ] ; Increment requiredSum by arr [ i ] ; Increment i by 1 ; Otherwise ; Increment count by 1 ; Increment requiredSum by requiredSum ; Return result ; Driver Code ; Input ; Function Call
using System ; class GFG { public static int minElements ( int [ ] arr , int N , int K ) { int count = 0 ; long requiredNum = 1 ; int i = 0 ; while ( requiredNum <= K ) { if ( i < N && requiredNum >= arr [ i ] ) { requiredNum += arr [ i ] ; i ++ ; } else { count ++ ; requiredNum += requiredNum ; } } return count ; } public static void Main ( string [ ] args ) { int [ ] arr = { 1 , 3 } ; int K = 6 ; int N = arr . Length ; Console . Write ( minElements ( arr , N , K ) ) ; } }
Maximize the count of adjacent element pairs with even sum by rearranging the Array | C # program for the above approach ; Function to find maximum count pair of adjacent elements with even sum ; Stores count of odd numbers ; Stores count of even numbers ; Traverse the array arr [ ] ; If arr [ i ] % 2 is 1 ; Else ; If odd and even both are greater than 0 ; Otherwise ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int maximumCount ( int [ ] arr , int N ) { int odd = 0 ; int even = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 != 0 ) odd ++ ; else even ++ ; } if ( odd != 0 && even != 0 ) return N - 2 ; else return N - 1 ; } public static void Main ( ) { int [ ] arr = { 9 , 13 , 15 , 3 , 16 , 9 , 13 , 18 } ; int N = arr . Length ; Console . Write ( maximumCount ( arr , N ) ) ; } }
Smallest number possible by repeatedly multiplying with K or 2 exactly N times starting from 1 | C # program for the above approach ; Function to find the minimum value of X after increment X by K or twice value of X in each of N operations ; Iterate over the range [ 1 , N ] ; If the value of X is less than equal to K ; Otherwise ; Return the minimum value of X ; Driver Code
using System ; class GFG { static int minPossibleValue ( int N , int K , int X ) { for ( int i = 1 ; i <= N ; i ++ ) { if ( X <= K ) { X = X * 2 ; } else { X = X + K ; } } return X ; } public static void Main ( ) { int N = 7 , K = 4 , X = 1 ; Console . WriteLine ( minPossibleValue ( N , K , X ) ) ; } }
Smallest number that can replace all | C # program for the above approach ; Function to find the value of K to minimize the value of maximum absolute difference between adjacent elements ; Stores the maximum and minimum among array elements that are adjacent to " - 1" ; Traverse the given array arr [ ] ; If arr [ i ] is - 1 & arr [ i + 1 ] is not - 1 ; If arr [ i + 1 ] is - 1 & arr [ i ] is not - 1 ; If all array element is - 1 ; Otherwise ; Driver Code
using System ; class GFG { public static void findMissingValue ( int [ ] arr , int N ) { int minE = Int32 . MaxValue , maxE = Int32 . MinValue ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] == - 1 && arr [ i + 1 ] != - 1 ) { minE = Math . Min ( minE , arr [ i + 1 ] ) ; maxE = Math . Max ( maxE , arr [ i + 1 ] ) ; } if ( arr [ i ] != - 1 && arr [ i + 1 ] == - 1 ) { minE = Math . Min ( minE , arr [ i ] ) ; maxE = Math . Max ( maxE , arr [ i ] ) ; } } if ( minE == Int32 . MaxValue && maxE == Int32 . MinValue ) { Console . WriteLine ( "0" ) ; } else { Console . WriteLine ( ( minE + maxE ) / 2 ) ; } } public static void Main ( ) { int [ ] arr = { 1 , - 1 , - 1 , - 1 , 5 } ; int N = arr . Length ; findMissingValue ( arr , N ) ; } }
Last element of an array after repeatedly removing the first element and appending it to the end of the array twice exactly K times | C # program for the above approach ; Function to find the last element after performing given operations ; Length of the array ; Increment j until condition is satisfied ; In each pair every value is repeating r number of times ; Print the result according to the value of k ; Driver Code ; Given K ; Given arr [ ] ; Function call
using System ; class GFG { static void findLastElement ( int N , int [ ] A ) { int l = A . Length ; int j = 0 ; while ( N > l * ( int ) ( Math . Pow ( 2 , j ) ) ) { N = N - l * ( int ) Math . Pow ( 2 , j ) ; j += 1 ; } int k = 1 ; int r = ( int ) Math . Pow ( 2 , j ) ; for ( int i = 1 ; i < l ; i ++ ) { if ( N > r * i ) k += 1 ; } for ( int i = 0 ; i < l ; i ++ ) { if ( i + 1 == k ) { Console . WriteLine ( A [ i ] ) ; return ; } } } public static void Main ( String [ ] args ) { int K = 7 ; int [ ] A = { 1 , 2 , 3 } ; findLastElement ( K , A ) ; } }
Minimum possible value of D which when added to or subtracted from K repeatedly obtains every array element | C # program for the above approach ; Recursive function tox previous gcd of a and b ; Function to find the maximum value of D such that every element in the array can be obtained by performing K + D or K - D ; Traverse the array arr [ ] ; Update arr [ i ] ; Stores GCD of the array ; Iterate over the range [ 1 , N ] ; Update the value of D ; Print the value of D ; Driver Code
using System ; class GFG { static int gcd ( int a , int b ) { if ( b == 0 ) return a ; return gcd ( b , a % b ) ; } static int findMaxD ( int [ ] arr , int N , int K ) { for ( int i = 0 ; i < N ; i ++ ) { arr [ i ] = Math . Abs ( arr [ i ] - K ) ; } int D = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { D = gcd ( D , arr [ i ] ) ; } return D ; } public static void Main ( ) { int [ ] arr = { 1 , 7 , 11 } ; int N = arr . Length ; int K = 3 ; Console . Write ( findMaxD ( arr , N , K ) ) ; } }
Maximize the number of times a character can be removed from substring 01 from given Binary String | C # program for the above approach ; Function to find the maximum moves that can be performed on a string ; Stores 0 s in suffix ; Stores 1 s in prefix ; Iterate over the characters of the string ; Iterate until i is greater than or equal to 0 ; If N is equal to x + y ; Return answer ; Driver code ; Input ; Function call
using System ; class GFG { static int maxOperations ( String S , int N ) { int X = 0 ; int Y = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == '0' ) break ; Y ++ ; } for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( S [ i ] == '1' ) break ; X ++ ; } if ( N == X + Y ) return 0 ; return N - ( X + Y ) - 1 ; } static void Main ( ) { String S = "001111" ; int N = S . Length ; Console . WriteLine ( maxOperations ( S , N ) ) ; } }
Maximize frequency sum of K chosen characters from given string | C # program for the above approach ; Function to find the maximum sum of frequencies of the exactly K chosen characters from the string S ; Stores the resultant maximum sum ; Stores the frequency of array elements ; Find the frequency of character ; Sort the frequency array in the descending order ; Iterate to choose K elements greedily ; If the freq [ i ] cards are chosen ; K cards have been picked ; Return the resultant sum ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int maximumSum ( string S , int N , int K ) { int sum = 0 ; int [ ] freq = new int [ 256 ] ; Array . Clear ( freq , 0 , 256 ) ; for ( int i = 0 ; i < N ; i ++ ) { freq [ ( int ) S [ i ] ] ++ ; } Array . Sort ( freq ) ; Array . Reverse ( freq ) ; for ( int i = 0 ; i < 256 ; i ++ ) { if ( K > freq [ i ] ) { sum += freq [ i ] * freq [ i ] ; K -= freq [ i ] ; } else { sum += freq [ i ] * K ; break ; } } return sum ; } public static void Main ( ) { string S = " GEEKSFORGEEKS " ; int K = 10 ; int N = S . Length ; Console . Write ( maximumSum ( S , N , K ) ) ; } }
Count of N | C # program for the above approach ; Function to count N - digit numbers having absolute difference between adjacent digits in non - increasing order ; If digit = n + 1 , a valid n - digit number has been formed ; If the state has already been computed ; If the current digit is 1 , then any digit from [ 1 - 9 ] can be placed ; If the current digit is 2 , any digit from [ 0 - 9 ] can be placed ; For other digits , any digit i can be placed which satisfies abs ( prev1 - i ) <= abs ( prev1 - prev2 ) ; If absolute difference is less than or equal to diff ; Function to count N - digit numbers with absolute difference between adjacent digits in non increasing order ; Initialize dp table with - 1 ; Function Call ; Driver code
using System ; class GFG { static int [ , , ] dp = new int [ 100 , 10 , 10 ] ; static int countOfNumbers ( int digit , int prev1 , int prev2 , int n ) { if ( digit == n + 1 ) { return 1 ; } int val = dp [ digit , prev1 , prev2 ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( digit == 1 ) { for ( int i = ( n == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } else if ( digit == 2 ) { for ( int i = 0 ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } else { int diff = Math . Abs ( prev2 - prev1 ) ; for ( int i = 0 ; i <= 9 ; ++ i ) { if ( Math . Abs ( prev1 - i ) <= diff ) { val += countOfNumbers ( digit + 1 , i , prev1 , n ) ; } } } return val ; } static void countNumbersUtil ( int N ) { for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { for ( int k = 0 ; k < 10 ; k ++ ) { dp [ i , j , k ] = - 1 ; } } } Console . WriteLine ( countOfNumbers ( 1 , 0 , 0 , N ) ) ; } static public void Main ( ) { int N = 3 ; countNumbersUtil ( N ) ; } }
Print all numbers that can be obtained by adding A or B to N exactly M times | C # program for the above approach ; Function to find all possible numbers that can be obtained by adding A or B to N exactly N times ; If number of steps is 0 and only possible number is N ; Add A to N and make a recursive call for M - 1 steps ; Add B to N and make a recursive call for M - 1 steps . ; Driver Code ; Given Inputs ; Stores all possible numbers ; Function call ; Print all possible numbers
using System ; using System . Collections . Generic ; public class MyClass { static void possibleNumbers ( HashSet < int > numbers , int N , int M , int A , int B ) { if ( M == 0 ) { numbers . Add ( N ) ; return ; } possibleNumbers ( numbers , N + A , M - 1 , A , B ) ; possibleNumbers ( numbers , N + B , M - 1 , A , B ) ; } public static void Main ( String [ ] args ) { int N = 5 , M = 3 , A = 4 , B = 6 ; HashSet < int > numbers = new HashSet < int > ( ) ; possibleNumbers ( numbers , N , M , A , B ) ; foreach ( int i in numbers ) Console . Write ( i + " ▁ " ) ; } }
Maximum sum of array after removing a positive or negative subarray | C # program for the above approach ; Function to find the maximum sum of array after removing either the contiguous positive or negative elements ; Store the total sum of array ; Store the maximum contiguous negative sum ; Store the sum of current contiguous negative elements ; Store the minimum element of array ; Traverse the array , arr [ ] ; Update the overall sum ; Store minimum element of array ; If arr [ i ] is positive ; Update temp_sum to 0 ; Add arr [ i ] to temp_sum ; Update max_neg ; If no negative element in array then remove smallest positive element ; Print the required sum ; Driver Code ; Given Input ; Function Call
using System ; class GFG { static void maxSum ( int [ ] arr , int n ) { int sum = 0 ; int max_neg = Int32 . MaxValue ; int tempsum = 0 ; int small = Int32 . MaxValue ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; small = Math . Min ( small , arr [ i ] ) ; if ( arr [ i ] > 0 ) { tempsum = 0 ; } else { tempsum += arr [ i ] ; } max_neg = Math . Min ( max_neg , tempsum ) ; } if ( max_neg == 0 ) { max_neg = small ; } Console . Write ( sum - max_neg ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 } ; int n = arr . Length ; maxSum ( arr , n ) ; } }
Lexicographically largest string possible by at most K replacements | C # implementation of the above approach ; Traverse each element of the string ; If the current character can be replaced with ' z ' ; Return the modified string ; Driver code
using System ; using System . Collections . Generic ; class GFG { static string largestString ( string s , int k ) { for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] != ' z ' && k > 0 ) { s = s . Replace ( s [ i ] , ' z ' ) ; k -- ; } } return s ; } public static void Main ( ) { string s = " dbza " ; int k = 1 ; Console . Write ( largestString ( s , k ) ) ; } }
Count characters of a string which when removed individually makes the string equal to another string | C # program for the above approach ; Function to count characters from string A whose removal makes the strings A and B equal ; Stores the index of the longest prefix ; Stores the index of the longest suffix ; Traverse the string B ; Traverse the string B ; If N - M is equal to 1 and Y is less than or equal to X ; Print the count of characters ; Print the positions of the characters ; Otherwise ; Driver Code
using System ; public class GFG { static void RemoveOneChar ( string A , string B , int N , int M ) { int X = 0 ; int Y = N - 1 ; for ( int i = 0 ; i < M ; i ++ ) { if ( A [ X ] != B [ i ] ) break ; X ++ ; } for ( int i = M - 1 ; i >= 0 ; i -- ) { if ( A [ Y ] != B [ i ] ) break ; Y -- ; } if ( N - M == 1 && Y < X ) { Console . WriteLine ( X - Y + 1 ) ; for ( int i = Y ; i <= X ; i ++ ) Console . Write ( i + 1 + " ▁ " ) ; Console . WriteLine ( ) ; } else Console . WriteLine ( - 1 ) ; } static public void Main ( ) { string A = " abaac " ; string B = " abac " ; int N = A . Length ; int M = B . Length ; RemoveOneChar ( A , B , N , M ) ; } }
Minimum flips or swapping of adjacent characters required to make a string equal to another | C # program for the above approach ; Function to find minimum operations required to convert string A to B ; Store the size of the string ; Store the required result ; Traverse the string , a ; If a [ i ] is equal to b [ i ] ; Check if swapping adjacent characters make the same - indexed characters equal or not ; Otherwise , flip the current bit ; Print the minimum number of operations ; Driver Code ; Given Input ; Function Call
using System ; class GFG { static void minimumOperation ( string a , string b ) { int n = a . Length ; int i = 0 ; int minoperation = 0 ; while ( i < n ) { if ( a [ i ] == b [ i ] ) { i = i + 1 ; continue ; } else if ( a [ i ] == b [ i + 1 ] && a [ i + 1 ] == b [ i ] && i < n - 1 ) { minoperation ++ ; i = i + 2 ; } else if ( a [ i ] != b [ i ] ) { minoperation ++ ; i = i + 1 ; } else { ++ i ; } } Console . WriteLine ( minoperation ) ; } public static void Main ( ) { string a = "10010010" , b = "00001000" ; minimumOperation ( a , b ) ; } }
Minimum replacements required to make sum of all K | C # program for the above approach ; Function to find minimum number of operations required to make sum of all subarrays of size K equal ; Stores number of operations ; Iterate in the range [ 0 , K - 1 ] ; Stores frequency of elements separated by distance K ; Stores maximum frequency and corresponding element ; Find max frequency element and its frequency ; Update the number of operations ; Print the result ; Driver Code ; Given Input ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void findMinOperations ( int [ ] arr , int N , int K ) { int operations = - 1 ; for ( int i = 0 ; i < K ; i ++ ) { Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; for ( int j = i ; j < N ; j += K ) { if ( freq . ContainsKey ( arr [ j ] ) ) freq [ arr [ j ] ] ++ ; else freq . Add ( arr [ j ] , 1 ) ; } int max1 = - 1 , num = 0 ; foreach ( KeyValuePair < int , int > entry in freq ) { if ( entry . Key > max1 ) { max1 = entry . Value ; num = entry . Key ; } } foreach ( KeyValuePair < int , int > entry in freq ) { if ( entry . Key != num ) operations += entry . Value ; } } Console . Write ( operations ) ; } public static void Main ( ) { int [ ] arr = { 3 , 4 , 3 , 5 , 6 } ; int K = 2 ; int N = arr . Length ; findMinOperations ( arr , N , K ) ; } }
Count of pairs of integers up to X and Y that generates equal Quotient and Remainder | C # Program for the above approach ; Function to calculate the number of pairs satisfying ( m / n = m % n ) ; Iterate from 1 to sqrt ( x ) ; Combining the conditions - 1 ) n > k 2 ) n <= y 3 ) n <= ( x / k - 1 ) ; Driver Code
using System ; public class GFG { static void countOfPairs ( int x , int y ) { int count = 0 ; for ( int k = 1 ; k * k <= x ; ++ k ) { count += Math . Max ( 0 , Math . Min ( y , x / k - 1 ) - k ) ; } Console . Write ( count ) ; } static public void Main ( ) { int x = 4 ; int y = 5 ; countOfPairs ( x , y ) ; } }
Count permutations of first N natural numbers having sum of adjacent elements equal to a perfect square | C # program for the above approach ; Function to count total number of permutation of the first N natural number having the sum of adjacent elements as perfect square ; Create an adjacency matrix ; Count elements whose indegree is 1 ; Generate adjacency matrix ; Find the sum of i and j ; If sum is perfect square . then move from i to j ; Add it in adjacency list of i ; If any list is of size 1 , then the indegree is 1 ; If there is no element whose indegree is 1 , then N such permutations are possible ; If there is 1 or 2 elements whose indegree is 1 , then 2 permutations are possible ; If there are more than 2 elements whose indegree is 1 , then return 0 ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int countPermutations ( int N ) { List < List < int > > adj = new List < List < int > > ( 105 ) ; for ( int i = 0 ; i < 105 ; i ++ ) adj . Add ( new List < int > ( ) ) ; int indeg = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { if ( i == j ) continue ; int sum = i + j ; if ( Math . Ceiling ( Math . Sqrt ( sum ) ) == Math . Floor ( Math . Sqrt ( sum ) ) ) { adj [ i ] . Add ( j ) ; } } if ( adj [ i ] . Count == 1 ) indeg ++ ; } if ( indeg == 0 ) return N ; else if ( indeg <= 2 ) return 2 ; else return 0 ; } public static void Main ( ) { int N = 17 ; Console . WriteLine ( countPermutations ( N ) ) ; } }
Generate a permutation of first N natural numbers having count of unique adjacent differences equal to K | C # program for the above approach ; Function to construct the list with exactly K unique adjacent element differences ; Stores the resultant array ; Stores the left and the right most element of the range ; Traverse the array ; If k is even , the add left to array and increment the left ; If k is odd , the add right to array and decrement the right ; Repeat the steps for k - 1 times ; Print the resultant list ; Driver Code
using System ; using System . Collections . Generic ; class GFG { public static void makeList ( int N , int K ) { int [ ] list = new int [ N ] ; int left = 1 ; int right = N ; for ( int i = 0 ; i < N ; i ++ ) { if ( K % 2 == 0 ) { list [ i ] = left ; left = left + 1 ; } else { list [ i ] = right ; right = right - 1 ; } if ( K > 1 ) K -- ; } for ( int i = 0 ; i < list . Length ; i ++ ) { Console . Write ( list [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int N = 6 ; int K = 3 ; makeList ( N , K ) ; } }
Find the date after next half year from a given date | C # program for the above approach ; Function to find the date after the next half - year ; Stores the number of days in the months of a leap year ; List of months ; Days in half of a year ; Index of current month ; Starting day ; Decrement the value of cnt by 1 ; Increment cur_date ; If cnt is equal to 0 , then break out of the loop ; Update cur_month ; Update cur_date ; Print the resultant date ; Driver Code ; Function Call
using System ; class GFG { static void getDate ( int d , string m ) { int [ ] days = { 31 , 29 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ; string [ ] month = { " January " , " February " , " March " , " April " , " May " , " June " , " July " , " August " , " September " , " October " , " November " , " December " } ; int cnt = 183 ; int cur_month = 0 ; for ( int i = 0 ; i < 12 ; i ++ ) if ( m == month [ i ] ) cur_month = i ; int cur_date = d ; while ( true ) { while ( cnt > 0 && cur_date <= days [ cur_month ] ) { cnt -= 1 ; cur_date += 1 ; } if ( cnt == 0 ) break ; cur_month = ( cur_month + 1 ) % 12 ; cur_date = 1 ; } Console . WriteLine ( cur_date + " ▁ " + month [ cur_month ] ) ; } public static void Main ( ) { int D = 15 ; string M = " January " ; getDate ( D , M ) ; } }
Maximum number made up of distinct digits whose sum is equal to N | C # program for the above approach ; Function to find the largest positive number made up of distinct digits having the sum of its digits as N ; If given number is greater than 45 , print - 1 ; Store the required number and the digit to be considered ; Loop until N > 0 and digit > 0 ; If the current digit is at most N then , add it to number num ; Update the value of num ; Decrement N by digit ; Consider the next lower digit ; Add 0 at the end and return the number num ; Driver Code
using System ; class GFG { static long largestNumber ( int N ) { if ( N > 45 ) return - 1 ; int num = 0 , digit = 9 ; while ( N > 0 && digit > 0 ) { if ( digit <= N ) { num *= 10 ; num += digit ; N -= digit ; } digit -= 1 ; } return num * 10 ; } public static void Main ( ) { int N = 25 ; Console . Write ( largestNumber ( N ) ) ; } }