codeparrot/xlcost-text-to-code huggingface dataset:
Check if an array can be split into 3 subsequences of equal sum or not | C # program for the above approach ; Utility function to check array can be partition to 3 subsequences of equal sum or not ; Base Case ; When element at index j is added to sm1 ; When element at index j is added to sm2 ; When element at index j is added to sm3 ; Return maximum value among all above 3 recursive call ; Function to check array can be partition to 3 subsequences of equal sum or not ; Initialise 3 sums to 0 ; Function Call ; Driver Code ; Given array arr [ ] ; Function Call
using System ; class GFG { static int checkEqualSumUtil ( int [ ] arr , int N , int sm1 , int sm2 , int sm3 , int j ) { if ( j == N ) { if ( sm1 == sm2 && sm2 == sm3 ) return 1 ; else return 0 ; } else { int l = checkEqualSumUtil ( arr , N , sm1 + arr [ j ] , sm2 , sm3 , j + 1 ) ; int m = checkEqualSumUtil ( arr , N , sm1 , sm2 + arr [ j ] , sm3 , j + 1 ) ; int r = checkEqualSumUtil ( arr , N , sm1 , sm2 , sm3 + arr [ j ] , j + 1 ) ; return Math . Max ( Math . Max ( l , m ) , r ) ; } } static void checkEqualSum ( int [ ] arr , int N ) { int sum1 , sum2 , sum3 ; sum1 = sum2 = sum3 = 0 ; if ( checkEqualSumUtil ( arr , N , sum1 , sum2 , sum3 , 0 ) == 1 ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } public static void Main ( ) { int [ ] arr = { 17 , 34 , 59 , 23 , 17 , 67 , 57 , 2 , 18 , 59 , 1 } ; int N = arr . Length ; checkEqualSum ( arr , N ) ; } }
Check if an array can be split into 3 subsequences of equal sum or not | C # program for the above approach ; Function to check array can be partition into sum of 3 equal ; Base Case ; If value at particular index is not - 1 then return value at that index which ensure no more further calls ; When element at index j is added to sm1 ; When element at index j is added to sm2 ; When element at index j is added to sm3 ; Update the current state and return that value ; Function to check array can be partition to 3 subsequences of equal sum or not ; Initialise 3 sums to 0 ; Function call ; Driver Code ; Given array arr [ ] ; Function call
using System ; using System . Collections . Generic ; class GFG { static Dictionary < string , int > dp = new Dictionary < string , int > ( ) ; static int checkEqualSumUtil ( int [ ] arr , int N , int sm1 , int sm2 , int sm3 , int j ) { string s = sm1 . ToString ( ) + " _ " + sm2 . ToString ( ) + j . ToString ( ) ; if ( j == N ) { if ( sm1 == sm2 && sm2 == sm3 ) return 1 ; else return 0 ; } if ( dp . ContainsKey ( s ) ) return dp [ s ] ; else { int l = checkEqualSumUtil ( arr , N , sm1 + arr [ j ] , sm2 , sm3 , j + 1 ) ; int m = checkEqualSumUtil ( arr , N , sm1 , sm2 + arr [ j ] , sm3 , j + 1 ) ; int r = checkEqualSumUtil ( arr , N , sm1 , sm2 , sm3 + arr [ j ] , j + 1 ) ; dp [ s ] = Math . Max ( Math . Max ( l , m ) , r ) ; return dp [ s ] ; } } static void checkEqualSum ( int [ ] arr , int N ) { int sum1 , sum2 , sum3 ; sum1 = sum2 = sum3 = 0 ; if ( checkEqualSumUtil ( arr , N , sum1 , sum2 , sum3 , 0 ) == 1 ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 17 , 34 , 59 , 23 , 17 , 67 , 57 , 2 , 18 , 59 , 1 } ; int N = arr . Length ; checkEqualSum ( arr , N ) ; } }
Smallest index in given range of indices which is not equal to X | C # program to find the smallest index in the array in the range [ L , R ] which does not contain X ; Precompute the index of next different element in the array for every array element ; Default value ; Compute nextpos [ i ] using nextpos [ i + 1 ] ; Function to return the smallest index ; nextpos [ i ] will store the next position p where arr [ p ] != arr [ i ] ; If X is not present at l ; Otherwise ; Find the index which stores a value different from X ; If that index is within the range ; Driver Code
using System ; class GFG { static void precompute ( int [ ] nextpos , int [ ] arr , int N ) { nextpos [ N - 1 ] = N ; for ( int i = N - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] == arr [ i + 1 ] ) nextpos [ i ] = nextpos [ i + 1 ] ; else nextpos [ i ] = i + 1 ; } } static void findIndex ( int [ , ] query , int [ ] arr , int N , int Q ) { int [ ] nextpos = new int [ N ] ; precompute ( nextpos , arr , N ) ; for ( int i = 0 ; i < Q ; i ++ ) { int l , r , x ; l = query [ i , 0 ] ; r = query [ i , 1 ] ; x = query [ i , 2 ] ; int ans = - 1 ; if ( arr [ l ] != x ) ans = l ; else { int d = nextpos [ l ] ; if ( d <= r ) ans = d ; } Console . Write ( ans + " STRNEWLINE " ) ; } } public static void Main ( String [ ] args ) { int N , Q ; N = 6 ; Q = 3 ; int [ ] arr = { 1 , 2 , 1 , 1 , 3 , 5 } ; int [ , ] query = { { 0 , 3 , 1 } , { 1 , 5 , 2 } , { 2 , 3 , 1 } } ; findIndex ( query , arr , N , Q ) ; } }
Count number of ways to convert string S to T by performing K cyclic shifts | C # program for the above approach ; Function to count number of ways to convert string S to string T by performing K cyclic shifts ; Calculate length of string ; ' a ' is no of good cyclic shifts ' b ' is no of bad cyclic shifts ; Iterate in the string ; Precompute the number of good and bad cyclic shifts ; dp2 [ i ] to store the no of ways to get to a bad shift in i moves ; Calculate good and bad shifts ; Return the required number of ways ; Driver code ; Given Strings ; Given K shifts required ; Function call
using System ; class GFG { static long mod = 10000000007L ; static long countWays ( string s , string t , int k ) { int n = s . Length ; int a = 0 , b = 0 ; for ( int i = 0 ; i < n ; i ++ ) { string p = s . Substring ( i , n - i ) + s . Substring ( 0 , i ) ; if ( p == t ) a ++ ; else b ++ ; } long [ ] dp1 = new long [ k + 1 ] ; long [ ] dp2 = new long [ k + 1 ] ; if ( s == t ) { dp1 [ 0 ] = 1 ; dp2 [ 0 ] = 0 ; } else { dp1 [ 0 ] = 0 ; dp2 [ 0 ] = 1 ; } for ( int i = 1 ; i <= k ; i ++ ) { dp1 [ i ] = ( ( dp1 [ i - 1 ] * ( a - 1 ) ) % mod + ( dp2 [ i - 1 ] * a ) % mod ) % mod ; dp2 [ i ] = ( ( dp1 [ i - 1 ] * ( b ) ) % mod + ( dp2 [ i - 1 ] * ( b - 1 ) ) % mod ) % mod ; } return dp1 [ k ] ; } public static void Main ( string [ ] args ) { string S = " ab " , T = " ab " ; int K = 2 ; Console . Write ( countWays ( S , T , K ) ) ; } }
Minimize steps to reach K from 0 by adding 1 or doubling at each step | C # program to implement the above approach ; Function to find minimum operations ; dp is initialised to store the steps ; For all even numbers ; Driver Code
using System ; class GFG { static int minOperation ( int k ) { int [ ] dp = new int [ k + 1 ] ; for ( int i = 1 ; i <= k ; i ++ ) { dp [ i ] = dp [ i - 1 ] + 1 ; if ( i % 2 == 0 ) { dp [ i ] = Math . Min ( dp [ i ] , dp [ i / 2 ] + 1 ) ; } } return dp [ k ] ; } public static void Main ( ) { int K = 12 ; Console . Write ( minOperation ( K ) ) ; } }
Find maximum subset sum formed by partitioning any subset of array into 2 partitions with equal sum | C # implementation for the above mentioned recursive approach ; Function to find the maximum subset sum ; Ignore the current element ; including element in partition 1 ; including element in partition 2 ; Driver code ; size of the array
using System ; public class GFG { static int maxSum ( int p0 , int p1 , int [ ] a , int pos , int n ) { if ( pos == n ) { if ( p0 == p1 ) return p0 ; else return 0 ; } int ans = maxSum ( p0 , p1 , a , pos + 1 , n ) ; ans = Math . Max ( ans , maxSum ( p0 + a [ pos ] , p1 , a , pos + 1 , n ) ) ; ans = Math . Max ( ans , maxSum ( p0 , p1 + a [ pos ] , a , pos + 1 , n ) ) ; return ans ; } public static void Main ( string [ ] args ) { int n = 4 ; int [ ] a = { 1 , 2 , 3 , 6 } ; Console . WriteLine ( maxSum ( 0 , 0 , a , 0 , n ) ) ; } }
Find maximum subset sum formed by partitioning any subset of array into 2 partitions with equal sum | C # implementation for the above mentioned Dynamic Programming approach ; Function to find the maximum subset sum ; sum of all elements ; bottom up lookup table ; ; initialising dp table with INT_MIN where , INT_MIN means no solution ; Case when diff is 0 ; Putting ith element in g0 ; Putting ith element in g1 ; Ignoring ith element ; Driver code
using System ; class GFG { static int INT_MIN = int . MinValue ; static int maxSum ( int [ ] a , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; int limit = 2 * sum + 1 ; int [ , ] dp = new int [ n + 1 , limit ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < limit ; j ++ ) dp [ i , j ] = INT_MIN ; } dp [ 0 , sum ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 0 ; j < limit ; j ++ ) { if ( ( j - a [ i - 1 ] ) >= 0 && dp [ i - 1 , j - a [ i - 1 ] ] != INT_MIN ) dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i - 1 , j - a [ i - 1 ] ] + a [ i - 1 ] ) ; if ( ( j + a [ i - 1 ] ) < limit && dp [ i - 1 , j + a [ i - 1 ] ] != INT_MIN ) dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i - 1 , j + a [ i - 1 ] ] ) ; if ( dp [ i - 1 , j ] != INT_MIN ) dp [ i , j ] = Math . Max ( dp [ i , j ] , dp [ i - 1 , j ] ) ; } } return dp [ n , sum ] ; } public static void Main ( ) { int n = 4 ; int [ ] a = { 1 , 2 , 3 , 6 } ; Console . WriteLine ( maxSum ( a , n ) ) ; } }
Count of strings possible by replacing two consecutive same character with new character | C # program to count the different possible string form by replacing two same characters with one ; Array to find the fibonacci sequence ; Function to find the fibonacci sequence ; Function to count all possible strings ; Initialize ans = 1 ; If two consecutive char are same increase cnt ; Else multiply the fib [ cnt ] to ans and initialize ans to 1 ; If str = abcdeeee , then for last " eeee " the count munst be updated ; Return the total count ; Driver 's Code ; Function to precompute all the fibonacci number ; Function call to find the count
using System ; class GFG { static int [ ] fib = new int [ 100005 ] ; static void computeFibonacci ( ) { fib [ 0 ] = 1 ; fib [ 1 ] = 1 ; for ( int i = 2 ; i < 100005 ; i ++ ) { fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } } static int countString ( string str ) { int ans = 1 ; int cnt = 1 ; for ( int i = 1 ; i < str . Length ; i ++ ) { if ( str [ i ] == str [ i - 1 ] ) { cnt ++ ; } else { ans = ans * fib [ cnt ] ; cnt = 1 ; } } ans = ans * fib [ cnt ] ; return ans ; } public static void Main ( string [ ] args ) { string str = " abdllldefkkkk " ; computeFibonacci ( ) ; Console . WriteLine ( countString ( str ) ) ; } }
Golomb Sequence | Set 2 | C # program to find the first N terms of Golomb Sequence ; Function to print the Golomb Sequence ; Initialise the array ; Initialise the cnt to 0 ; First and second element of Golomb Sequence is 0 , 1 ; Map to store the count of current element in Golomb Sequence ; Store the count of 2 ; Iterate over 2 to N ; If cnt is equals to 0 then we have new number for Golomb Sequence 1 2 2 3 3 4 4 4 5 5 5 which is 1 + previous element ; Else the current element is the previous element in this Sequence ; Map the current index to current value in arr [ ] ; Print the Golomb Sequence ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int MAX = 1000 ; static void printGolombSequence ( int N ) { int [ ] arr = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) arr [ i ] = 0 ; int cnt = 0 ; arr [ 0 ] = 0 ; arr [ 1 ] = 1 ; Dictionary < int , int > M = new Dictionary < int , int > ( ) ; M . Add ( 2 , 2 ) ; for ( int i = 2 ; i <= N ; i ++ ) { if ( cnt == 0 ) { arr [ i ] = 1 + arr [ i - 1 ] ; cnt = M [ arr [ i ] ] ; cnt -- ; } else { arr [ i ] = arr [ i - 1 ] ; cnt -- ; } if ( M . ContainsKey ( i ) ) { M [ i ] = arr [ i ] ; } else { M . Add ( i , arr [ i ] ) ; } } for ( int i = 1 ; i <= N ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } static void Main ( ) { int N = 11 ; printGolombSequence ( N ) ; } }
Count ways to reach Nth Stairs by taking 1 and 2 steps with exactly one 3 step | C # implementation to find the number the number of ways to reach Nth stair by taking 1 , 2 step at a time and 3 Steps at a time exactly once . ; Function to find the number the number of ways to reach Nth stair ; Array including number of ways that includes 3 ; Array including number of ways that doesn 't includes 3 ; Initially to reach 3 stairs by taking 3 steps can be reached by 1 way ; Loop to find the number the number of ways to reach Nth stair ; Driver Code
using System ; class GFG { static int number_of_ways ( int n ) { int [ ] includes_3 = new int [ n + 1 ] ; int [ ] not_includes_3 = new int [ n + 1 ] ; includes_3 [ 3 ] = 1 ; not_includes_3 [ 1 ] = 1 ; not_includes_3 [ 2 ] = 2 ; not_includes_3 [ 3 ] = 3 ; for ( int i = 4 ; i <= n ; i ++ ) { includes_3 [ i ] = includes_3 [ i - 1 ] + includes_3 [ i - 2 ] + not_includes_3 [ i - 3 ] ; not_includes_3 [ i ] = not_includes_3 [ i - 1 ] + not_includes_3 [ i - 2 ] ; } return includes_3 [ n ] ; } public static void Main ( String [ ] args ) { int n = 7 ; Console . Write ( number_of_ways ( n ) ) ; } }
Maximum number of multiples in an array before any element | C # implementation of the approach ; Map to store the divisor count ; Function to generate the divisors of all the array elements ; Function to find the maximum number of multiples in an array before it ; To store the maximum divisor count ; Update ans if more number of divisors are found ; Generating all the divisors of the next element of the array ; Driver code
using System ; class GFG { static int MAX = 100000 ; static int [ ] divisors = new int [ MAX ] ; static void generateDivisors ( int n ) { for ( int i = 1 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { divisors [ i ] ++ ; } else { divisors [ i ] ++ ; divisors [ n / i ] ++ ; } } } } static int findMaxMultiples ( int [ ] arr , int n ) { int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans = Math . Max ( divisors [ arr [ i ] ] , ans ) ; generateDivisors ( arr [ i ] ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 8 , 1 , 28 , 4 , 2 , 6 , 7 } ; int n = arr . Length ; Console . Write ( findMaxMultiples ( arr , n ) ) ; } }
Number of ways to reach the end of matrix with non | C # implementation of the approach ; 3d array to store states of dp ; Array to determine whether a state has been solved before ; Function to return the count of required paths ; Base cases ; If a state has been solved before it won 't be evaluated again ; Recurrence relation ; Driver code
using System ; class GFG { static int n = 3 ; static int maxV = 20 ; static int [ , , ] dp = new int [ n , n , maxV ] ; static int [ , , ] v = new int [ n , n , maxV ] ; static int countWays ( int i , int j , int x , int [ , ] arr ) { if ( i == n j == n ) { return 0 ; } x = ( x & arr [ i , j ] ) ; if ( x == 0 ) { return 0 ; } if ( i == n - 1 && j == n - 1 ) { return 1 ; } if ( v [ i , j , x ] == 1 ) { return dp [ i , j , x ] ; } v [ i , j , x ] = 1 ; dp [ i , j , x ] = countWays ( i + 1 , j , x , arr ) + countWays ( i , j + 1 , x , arr ) ; return dp [ i , j , x ] ; } public static void Main ( ) { int [ , ] arr = { { 1 , 2 , 1 } , { 1 , 1 , 0 } , { 2 , 1 , 1 } } ; Console . WriteLine ( countWays ( 0 , 0 , arr [ 0 , 0 ] , arr ) ) ; } }
Maximum sum from three arrays such that picking elements consecutively from same is not allowed | C # program for the above approach ; Function to return the maximum sum ; Base case ; Already visited ; If the element has been taken from first array in previous step ; If the element has been taken from second array in previous step ; If the element has been taken from third array in previous step ; Driver code ; Pick element from first array ; Pick element from second array ; Pick element from third array ; Print the maximum of them
using System ; class GFG { static int N = 3 ; static int FindMaximumSum ( int ind , int kon , int [ ] a , int [ ] b , int [ ] c , int n , int [ , ] dp ) { if ( ind == n ) return 0 ; if ( dp [ ind , kon ] != - 1 ) return dp [ ind , kon ] ; int ans = ( int ) ( - 1e9 + 5 ) ; if ( kon == 0 ) { ans = Math . Max ( ans , b [ ind ] + FindMaximumSum ( ind + 1 , 1 , a , b , c , n , dp ) ) ; ans = Math . Max ( ans , c [ ind ] + FindMaximumSum ( ind + 1 , 2 , a , b , c , n , dp ) ) ; } else if ( kon == 1 ) { ans = Math . Max ( ans , a [ ind ] + FindMaximumSum ( ind + 1 , 0 , a , b , c , n , dp ) ) ; ans = Math . Max ( ans , c [ ind ] + FindMaximumSum ( ind + 1 , 2 , a , b , c , n , dp ) ) ; } else if ( kon == 2 ) { ans = Math . Max ( ans , a [ ind ] + FindMaximumSum ( ind + 1 , 1 , a , b , c , n , dp ) ) ; ans = Math . Max ( ans , b [ ind ] + FindMaximumSum ( ind + 1 , 0 , a , b , c , n , dp ) ) ; } return dp [ ind , kon ] = ans ; } public static void Main ( ) { int [ ] a = { 6 , 8 , 2 , 7 , 4 , 2 , 7 } ; int [ ] b = { 7 , 8 , 5 , 8 , 6 , 3 , 5 } ; int [ ] c = { 8 , 3 , 2 , 6 , 8 , 4 , 1 } ; int n = a . Length ; int [ , ] dp = new int [ n , N ] ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { dp [ i , j ] = - 1 ; } } int x = FindMaximumSum ( 0 , 0 , a , b , c , n , dp ) ; int y = FindMaximumSum ( 0 , 1 , a , b , c , n , dp ) ; int z = FindMaximumSum ( 0 , 2 , a , b , c , n , dp ) ; Console . WriteLine ( Math . Max ( x , Math . Max ( y , z ) ) ) ; } }
Number of ways to make binary string of length N such that 0 s always occur together in groups of size K | C # implementation of the approach ; Function to return no of ways to build a binary string of length N such that 0 s always occur in groups of size K ; Driver Code
using System ; class GFG { static int mod = 1000000007 ; static int noOfBinaryStrings ( int N , int k ) { int [ ] dp = new int [ 100002 ] ; for ( int i = 1 ; i <= k - 1 ; i ++ ) { dp [ i ] = 1 ; } dp [ k ] = 2 ; for ( int i = k + 1 ; i <= N ; i ++ ) { dp [ i ] = ( dp [ i - 1 ] + dp [ i - k ] ) % mod ; } return dp [ N ] ; } public static void Main ( ) { int N = 4 ; int K = 2 ; Console . WriteLine ( noOfBinaryStrings ( N , K ) ) ; } }
Number of ways to pair people | C # program to find number of ways to pair people in party ; Function to find number of ways to pair people in party ; To store count of number of ways . ; Using the recurrence defined find count for different values of p . ; Driver code
using System ; class GFG { public static int findWaysToPair ( int p ) { int [ ] dp = new int [ p + 1 ] ; dp [ 1 ] = 1 ; dp [ 2 ] = 2 ; for ( int i = 3 ; i <= p ; i ++ ) { dp [ i ] = dp [ i - 1 ] + ( i - 1 ) * dp [ i - 2 ] ; } return dp [ p ] ; } public static void Main ( string [ ] args ) { int p = 3 ; Console . WriteLine ( findWaysToPair ( p ) ) ; } }
Count ways to reach a score using 1 and 2 with no consecutive 2 s | A simple recursive implementation for counting ways to reach a score using 1 and 2 with consecutive 2 allowed ; base cases ; For cases n > 2 ; Driver Code
using System ; class GFG { static int CountWays ( int n ) { if ( n == 0 ) { return 1 ; } if ( n == 1 ) { return 1 ; } if ( n == 2 ) { return 1 + 1 ; } return CountWays ( n - 1 ) + CountWays ( n - 3 ) ; } static public void Main ( ) { int n = 5 ; Console . WriteLine ( CountWays ( n ) ) ; } }
Weird Number | C # program to check if the number is weird or not ; code to find all the factors of the number excluding the number itself ; List to store the factors ; note that this loop runs till sqrt ( n ) ; if the value of i is a factor ; condition to check the divisor is not the number itself ; return the List ; Function to check if the number is abundant or not ; find the divisors using function ; sum all the factors ; check for abundant or not ; Function to check if the number is semi - perfect or not ; find the divisors ; sorting the List ; subset to check if no is semiperfect ; initialising 1 st column to true ; initialing 1 st row except zero position to 0 ; loop to find whether the number is semiperfect ; calculation to check if the number can be made by summation of divisors ; if not possible to make the number by any combination of divisors ; Function to check for weird or not ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static List < int > factors ( int n ) { List < int > v = new List < int > ( ) ; v . Add ( 1 ) ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v . Add ( i ) ; if ( n / i != i ) { v . Add ( n / i ) ; } } } return v ; } static Boolean checkAbundant ( int n ) { List < int > v ; int sum = 0 ; v = factors ( n ) ; for ( int i = 0 ; i < v . Count ; i ++ ) { sum += v [ i ] ; } if ( sum > n ) return true ; else return false ; } static Boolean checkSemiPerfect ( int n ) { List < int > v ; v = factors ( n ) ; v . Sort ( ) ; int r = v . Count ; Boolean [ , ] subset = new Boolean [ r + 1 , n + 1 ] ; for ( int i = 0 ; i <= r ; i ++ ) subset [ i , 0 ] = true ; for ( int i = 1 ; i <= n ; i ++ ) subset [ 0 , i ] = false ; for ( int i = 1 ; i <= r ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( j < v [ i - 1 ] ) subset [ i , j ] = subset [ i - 1 , j ] ; else { subset [ i , j ] = subset [ i - 1 , j ] || subset [ i - 1 , j - v [ i - 1 ] ] ; } } } if ( ( subset [ r , n ] ) == false ) return false ; else return true ; } static Boolean checkweird ( int n ) { if ( checkAbundant ( n ) == true && checkSemiPerfect ( n ) == false ) return true ; else return false ; } public static void Main ( String [ ] args ) { int n = 70 ; if ( checkweird ( n ) ) Console . WriteLine ( " Weird ▁ Number " ) ; else Console . WriteLine ( " Not ▁ Weird ▁ Number " ) ; } }
Maximum subarray sum in an array created after repeated concatenation | C # program to print largest contiguous array sum when array is created after concatenating a small array k times . ; Returns sum of maximum sum subarray created after concatenating a [ 0. . n - 1 ] k times . ; This is where it differs from Kadane 's algorithm. We use modular  arithmetic to find next element. ; Driver Code
using System ; class GFG { static int maxSubArraySumRepeated ( int [ ] a , int n , int k ) { int max_so_far = 0 ; int max_ending_here = 0 ; for ( int i = 0 ; i < n * k ; i ++ ) { max_ending_here = max_ending_here + a [ i % n ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } public static void Main ( ) { int [ ] a = { 10 , 20 , - 30 , - 1 } ; int n = a . Length ; int k = 3 ; Console . Write ( " Maximum ▁ contiguous ▁ sum ▁ is ▁ " + maxSubArraySumRepeated ( a , n , k ) ) ; } }
Longest Increasing Odd Even Subsequence | C # implementation to find the longest increasing odd even subsequence ; function to find the longest increasing odd even subsequence ; lioes [ i ] stores longest increasing odd even subsequence ending at arr [ i ] ; to store the length of longest increasing odd even subsequence ; Initialize LIOES values for all indexes ; Compute optimized LIOES values in bottom up manner ; Pick maximum of all LIOES values ; required maximum length ; driver function
using System ; class GFG { public static int longOddEvenIncSeq ( int [ ] arr , int n ) { int [ ] lioes = new int [ n ] ; int maxLen = 0 ; for ( int i = 0 ; i < n ; i ++ ) lioes [ i ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1 ; for ( int i = 0 ; i < n ; i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ] ; return maxLen ; } public static void Main ( ) { int [ ] arr = new int [ ] { 1 , 12 , 2 , 22 , 5 , 30 , 31 , 14 , 17 , 11 } ; int n = 10 ; Console . Write ( " Longest ▁ Increasing ▁ Odd " + " ▁ Even ▁ Subsequence : ▁ " + longOddEvenIncSeq ( arr , n ) ) ; } }