codeparrot/xlcost-text-to-code huggingface dataset:
Maximum in an array that can make another array sorted | C # program to make array sorted ; Function to check whether there is any swappable element present to make the first array sorted ; wrongIdx is the index of the element which is making the first array unsorted ; Find the maximum element which satisfies the above mentioned neighboring conditions ; if res is true then swap the element and make the first array sorted ; Function to print the sorted array if elements are swapped . ; Driver Code
using System ; class GFG { static bool swapElement ( int [ ] arr1 , int [ ] arr2 , int n ) { int wrongIdx = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr1 [ i ] < arr1 [ i - 1 ] ) { wrongIdx = i ; } } int maximum = int . MinValue ; int maxIdx = - 1 ; bool res = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr2 [ i ] > maximum && arr2 [ i ] >= arr1 [ wrongIdx - 1 ] ) { if ( wrongIdx + 1 <= n - 1 && arr2 [ i ] <= arr1 [ wrongIdx + 1 ] ) { maximum = arr2 [ i ] ; maxIdx = i ; res = true ; } } } if ( res ) { swap ( arr1 , wrongIdx , arr2 , maxIdx ) ; } return res ; } static void swap ( int [ ] a , int wrongIdx , int [ ] b , int maxIdx ) { int c = a [ wrongIdx ] ; a [ wrongIdx ] = b [ maxIdx ] ; b [ maxIdx ] = c ; } static void getSortedArray ( int [ ] arr1 , int [ ] arr2 , int n ) { if ( swapElement ( arr1 , arr2 , n ) ) { for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( arr1 [ i ] + " ▁ " ) ; } } else { Console . Write ( " Not ▁ Possible " ) ; } } public static void Main ( ) { int [ ] arr1 = { 1 , 3 , 7 , 4 , 10 } ; int [ ] arr2 = { 2 , 1 , 6 , 8 , 9 } ; int n = arr1 . Length ; getSortedArray ( arr1 , arr2 , n ) ; } }
Middle of three using minimum comparisons | C # program to find middle of three distinct numbers ; Function to find the middle of three number ; Compare each three number to find middle number . Enter only if a > b ; Decided a is not greater than b . ; Driver code
using System ; class Middle { public static int middleOfThree ( int a , int b , int c ) { if ( a > b ) { if ( b > c ) return b ; else if ( a > c ) return c ; else return a ; } else { if ( a > c ) return a ; else if ( b > c ) return c ; else return b ; } } public static void Main ( ) { int a = 20 , b = 30 , c = 40 ; Console . WriteLine ( middleOfThree ( a , b , c ) ) ; } }
Largest area possible after removal of a series of horizontal & vertical bars | C # program for the above approach ; Function to find the largest area when a series of horizontal & vertical bars are removed ; Stores all bars ; Insert horizontal bars ; Insert vertictal bars ; Remove horizontal separators from s1 ; Remove vertical separators from s2 ; Stores left out horizontal and vertical separators ; Sort both list in ascending order ; Find maximum difference of neighbors of list1 ; Find max difference of neighbors of list2 ; Print largest volume ; Driver code ; Given value of N & M ; Given arrays ; Function call to find the largest area when a series of horizontal & vertical bars are removed
using System ; using System . Collections . Generic ; class GFG { static void largestArea ( int N , int M , int [ ] H , int [ ] V ) { HashSet < int > s1 = new HashSet < int > ( ) ; HashSet < int > s2 = new HashSet < int > ( ) ; for ( int i = 1 ; i <= N + 1 ; i ++ ) s1 . Add ( i ) ; for ( int i = 1 ; i <= M + 1 ; i ++ ) s2 . Add ( i ) ; for ( int i = 0 ; i < H . Length ; i ++ ) { s1 . Remove ( H [ i ] ) ; } for ( int i = 0 ; i < V . Length ; i ++ ) { s2 . Remove ( V [ i ] ) ; } int [ ] list1 = new int [ s1 . Count ] ; int [ ] list2 = new int [ s2 . Count ] ; int I = 0 ; foreach ( int it1 in s1 ) { list1 [ I ++ ] = it1 ; } I = 0 ; foreach ( int it2 in s2 ) { list2 [ I ++ ] = it2 ; } Array . Sort ( list1 ) ; Array . Sort ( list2 ) ; int maxH = 0 , p1 = 0 , maxV = 0 , p2 = 0 ; for ( int j = 0 ; j < list1 . Length ; j ++ ) { maxH = Math . Max ( maxH , list1 [ j ] - p1 ) ; p1 = list1 [ j ] ; } for ( int j = 0 ; j < list2 . Length ; j ++ ) { maxV = Math . Max ( maxV , list2 [ j ] - p2 ) ; p2 = list2 [ j ] ; } Console . WriteLine ( maxV * maxH ) ; } static void Main ( ) { int N = 3 , M = 3 ; int [ ] H = { 2 } ; int [ ] V = { 2 } ; largestArea ( N , M , H , V ) ; } }
Check if an array can be sorted by swapping pairs from indices consisting of unequal elements in another array | C # program of the above approach ; Function to check if array , A [ ] can be converted into sorted array by swapping ( A [ i ] , A [ j ] ) if B [ i ] not equal to B [ j ] ; Stores if array A [ ] is sorted in descending order or not ; Traverse the array A [ ] ; If A [ i ] is greater than A [ i + 1 ] ; Update flag ; If array is sorted in ascending order ; count = 2 : Check if 0 s and 1 s both present in the B [ ] ; Traverse the array ; If current element is 0 ; Update count ; Traverse the array B [ ] ; If current element is 1 ; If both 0 s and 1 s are present in the array ; Driver Code ; Input array A [ ] ; Input array B [ ] ; Function call ; If true , print YES ; Else print NO
using System ; public class GFG { static bool checkifSorted ( int [ ] A , int [ ] B , int N ) { bool flag = false ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( A [ i ] > A [ i + 1 ] ) { flag = true ; break ; } } if ( ! flag ) { return true ; } int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( B [ i ] == 0 ) { count ++ ; break ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( B [ i ] == 1 ) { count ++ ; break ; } } if ( count == 2 ) { return true ; } return false ; } public static void Main ( string [ ] args ) { int [ ] A = { 3 , 1 , 2 } ; int [ ] B = { 0 , 1 , 1 } ; int N = A . Length ; bool check = checkifSorted ( A , B , N ) ; if ( check ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }
Minimum swaps required between two strings to make one string strictly greater than the other | C # program for above approach ; Function to find the minimum number of steps to make A > B ; If all character are same and M <= N ; If there lies any character in B which is greater than B [ 0 ] ; If there lies any character in A which is smaller than A [ 0 ] ; If there lies a character which is in A and greater than A [ 0 ] ; If there lies a character which is in B and less than B [ 0 ] ; Otherwise ; Driver function
using System ; using System . Text ; public class GFG { static int minSteps ( StringBuilder A , StringBuilder B , int M , int N ) { if ( A [ 0 ] > B [ 0 ] ) return 0 ; if ( B [ 0 ] > A [ 0 ] ) { return 1 ; } if ( M <= N && A [ 0 ] == B [ 0 ] && count ( A , A [ 0 ] ) == M && count ( B , B [ 0 ] ) == N ) return - 1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( B [ i ] > B [ 0 ] ) return 1 ; } for ( int i = 1 ; i < M ; i ++ ) { if ( A [ i ] < A [ 0 ] ) return 1 ; } for ( int i = 1 ; i < M ; i ++ ) { if ( A [ i ] > A [ 0 ] ) { swap ( A , i , B , 0 ) ; swap ( A , 0 , B , 0 ) ; return 2 ; } } for ( int i = 1 ; i < N ; i ++ ) { if ( B [ i ] < B [ 0 ] ) { swap ( A , 0 , B , i ) ; swap ( A , 0 , B , 0 ) ; return 2 ; } } return 0 ; } static int count ( StringBuilder a , char c ) { int count = 0 ; for ( int i = 0 ; i < a . Length ; i ++ ) if ( a [ i ] == c ) count ++ ; return count ; } static void swap ( StringBuilder s1 , int index1 , StringBuilder s2 , int index2 ) { char c = s1 [ index1 ] ; s1 [ index1 ] = s2 [ index2 ] ; s2 [ index2 ] = c ; } static public void Main ( ) { StringBuilder A = new StringBuilder ( " adsfd " ) ; StringBuilder B = new StringBuilder ( " dffff " ) ; int M = A . Length ; int N = B . Length ; Console . WriteLine ( minSteps ( A , B , M , N ) ) ; } }
Maximize sum of pairwise products generated from the given Arrays | C # program for above approach ; Variables which represent the size of the array ; Stores the results ; Function to return the maximum possible sum ; Stores the count of arrays processed ; If more than two arrays have been processed ; If an already computed subproblem occurred ; Explore all the possible pairs ; Recursive function call ; Memoize the maximum ; Returning the value ; Function to return the maximum sum of products of pairs possible ; Initialising the dp array to - 1 ; Sort the arrays in descending order ; Driver Code
using System ; class GFG { const int maxN = 201 ; static int n1 , n2 , n3 ; static int [ , , ] dp = new int [ maxN , maxN , maxN ] ; static int getMaxSum ( int i , int j , int k , int [ ] arr1 , int [ ] arr2 , int [ ] arr3 ) { int cnt = 0 ; if ( i >= n1 ) cnt ++ ; if ( j >= n2 ) cnt ++ ; if ( k >= n3 ) cnt ++ ; if ( cnt >= 2 ) return 0 ; if ( dp [ i , j , k ] != - 1 ) return dp [ i , j , k ] ; int ans = 0 ; if ( i < n1 && j < n2 ) ans = Math . Max ( ans , getMaxSum ( i + 1 , j + 1 , k , arr1 , arr2 , arr3 ) + arr1 [ i ] * arr2 [ j ] ) ; if ( i < n1 && k < n3 ) ans = Math . Max ( ans , getMaxSum ( i + 1 , j , k + 1 , arr1 , arr2 , arr3 ) + arr1 [ i ] * arr3 [ k ] ) ; if ( j < n2 && k < n3 ) ans = Math . Max ( ans , getMaxSum ( i , j + 1 , k + 1 , arr1 , arr2 , arr3 ) + arr2 [ j ] * arr3 [ k ] ) ; dp [ i , j , k ] = ans ; return dp [ i , j , k ] ; } static void reverse ( int [ ] tmp ) { int i , t ; int n = tmp . Length ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = tmp [ i ] ; tmp [ i ] = tmp [ n - i - 1 ] ; tmp [ n - i - 1 ] = t ; } } static int maxProductSum ( int [ ] arr1 , int [ ] arr2 , int [ ] arr3 ) { for ( int i = 0 ; i < maxN ; i ++ ) for ( int j = 0 ; j < maxN ; j ++ ) for ( int k = 0 ; k < maxN ; k ++ ) dp [ i , j , k ] = - 1 ; Array . Sort ( arr1 ) ; reverse ( arr1 ) ; Array . Sort ( arr2 ) ; reverse ( arr2 ) ; Array . Sort ( arr3 ) ; reverse ( arr3 ) ; return getMaxSum ( 0 , 0 , 0 , arr1 , arr2 , arr3 ) ; } public static void Main ( string [ ] args ) { n1 = 2 ; int [ ] arr1 = { 3 , 5 } ; n2 = 2 ; int [ ] arr2 = { 2 , 1 } ; n3 = 3 ; int [ ] arr3 = { 4 , 3 , 5 } ; Console . Write ( maxProductSum ( arr1 , arr2 , arr3 ) ) ; } }
Largest lexicographic triplet from a given Array that forms a triangle | C # program to implement the the above approach ; Function to find lexicographically largest triplet that forms a triangle in the given array ; Sort the array ; Iterate from the end of the array ; If the triplet forms a triangle ; If triplet found ; Print the triplet ; Otherwise ; Driver Code
using System ; class GFG { static void findTriplet ( int [ ] arr , int N ) { Array . Sort ( arr ) ; int flag = 0 , i ; for ( i = N - 1 ; i - 2 >= 0 ; i -- ) { if ( arr [ i - 2 ] + arr [ i - 1 ] > arr [ i ] ) { flag = 1 ; break ; } } if ( flag != 0 ) { Console . Write ( arr [ i - 2 ] + " ▁ " + arr [ i - 1 ] + " ▁ " + arr [ i ] ) ; } else { Console . Write ( - 1 ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 4 , 2 , 10 , 3 , 5 } ; int N = arr . Length ; findTriplet ( arr , N ) ; } }
Count of all pairs in an Array with minimum absolute difference | C # program for the above approach ; Function to return the count of all pairs having minimal absolute difference ; Stores the count of pairs ; Sort the array ; Stores the minimum difference between adjacent pairs ; Update the minimum difference between pairs ; Increase count of pairs with difference equal to that of minimum difference ; Return the final count ; Driver Code ; Given array arr [ ] ; Function Call
using System ; class GFG { static int numberofpairs ( int [ ] arr , int N ) { int answer = 0 ; Array . Sort ( arr ) ; int minDiff = 10000000 ; for ( int i = 0 ; i < N - 1 ; i ++ ) minDiff = Math . Min ( minDiff , arr [ i + 1 ] - arr [ i ] ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i + 1 ] - arr [ i ] == minDiff ) answer ++ ; } return answer ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 2 , 1 , 3 } ; int N = arr . Length ; Console . Write ( numberofpairs ( arr , N ) ) ; } }
Maximum size subset with given sum using Backtracking | C # program to implement the above approach ; Initialise maximum possible length of subsequence ; Store elements to compare max_length with its size and change the value of max_length accordingly ; Store the elements of the longest subsequence ; Function to find the length of longest subsequence ; Update max_length ; Store the subsequence elements ; Recursively proceed with obtained sum ; poping elements from back of vector store ; If sum > 0 then we don 't  required thatsubsequence  so return and continue  with earlier elements ; Sort the given array ; Traverse the array ; If max_length is already greater than or equal than remaining length ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int max_length = 0 ; static List < int > store = new List < int > ( ) ; static List < int > ans = new List < int > ( ) ; static void find_max_length ( int [ ] arr , int index , int sum , int k ) { sum = sum + arr [ index ] ; store . Add ( arr [ index ] ) ; if ( sum == k ) { if ( max_length < store . Count ) { max_length = store . Count ; ans = store ; } } for ( int i = index + 1 ; i < arr . Length ; i ++ ) { if ( sum + arr [ i ] <= k ) { find_max_length ( arr , i , sum , k ) ; store . RemoveAt ( store . Count - 1 ) ; } else return ; } return ; } static int longestSubsequence ( int [ ] arr , int n , int k ) { Array . Sort ( arr ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( max_length >= n - i ) break ; store . Clear ( ) ; find_max_length ( arr , i , 0 , k ) ; } return max_length ; } public static void Main ( String [ ] args ) { int [ ] arr = { - 3 , 0 , 1 , 1 , 2 } ; int n = arr . Length ; int k = 1 ; Console . Write ( longestSubsequence ( arr , n , k ) ) ; } }
Sort decreasing permutation of N using triple swaps | C # implementation to sort decreasing permutation of N using triple swaps ; Function to sort array ; The three indices that has to be chosen ; Check if possible to sort array ; Swapping to bring element at required position Bringing at least one element at correct position ; Tracing changes in array ; Print the sorted array ; If not possible to sort ; Driver code
using System ; class GFG { static void sortArray ( int [ ] A , int N ) { int x = 0 , y = 0 , z = 0 ; if ( N % 4 == 0 N % 4 == 1 ) { for ( int i = 0 ; i < N / 2 ; i ++ ) { x = i ; if ( i % 2 == 0 ) { y = N - i - 2 ; z = N - i - 1 ; } A [ z ] = A [ y ] ; A [ y ] = A [ x ] ; A [ x ] = x + 1 ; } Console . Write ( " Sorted ▁ Array : ▁ " ) ; for ( int i = 0 ; i < N ; i ++ ) Console . Write ( A [ i ] + " ▁ " ) ; } else { Console . Write ( " - 1" ) ; } } public static void Main ( String [ ] args ) { int [ ] A = { 5 , 4 , 3 , 2 , 1 } ; int N = A . Length ; sortArray ( A , N ) ; } }
Find K such that changing all elements of the Array greater than K to K will make array sum N | C # implementation of the above approach ; Function to return K such that changing all elements greater than K to K will make array sum N otherwise return - 1 ; Sorting the array in increasing order ; Loop through all the elements of the array ; Checking if sum of array equals N ; Driver code
using System ; class GFG { static int findK ( int [ ] arr , int size , int N ) { Array . Sort ( arr ) ; int temp_sum = 0 ; for ( int i = 0 ; i < size ; i ++ ) { temp_sum += arr [ i ] ; if ( N - temp_sum == arr [ i ] * ( size - i - 1 ) ) { return arr [ i ] ; } } return - 1 ; } public static void Main ( ) { int [ ] arr = { 3 , 1 , 10 , 4 , 8 } ; int size = arr . Length ; int N = 16 ; Console . Write ( findK ( arr , size , N ) ) ; } }
Find three element from given three arrays such that their sum is X | Set 2 | C # implementation of the approach ; Function that returns true if there exists a triplet with sum x ; Sorting arrays such that a [ ] represents smallest array ; Iterating the smallest array ; Two pointers on second and third array ; If a valid triplet is found ;  ; Driver code
using System ; class GFG { static bool existsTriplet ( int [ ] a , int [ ] b , int [ ] c , int x , int l1 , int l2 , int l3 ) { if ( l2 <= l1 && l2 <= l3 ) { swap ( l2 , l1 ) ; swap ( a , b ) ; } else if ( l3 <= l1 && l3 <= l2 ) { swap ( l3 , l1 ) ; swap ( a , c ) ; } for ( int i = 0 ; i < l1 ; i ++ ) { int j = 0 , k = l3 - 1 ; while ( j < l2 && k >= 0 ) { if ( a [ i ] + b [ j ] + c [ k ] == x ) return true ; if ( a [ i ] + b [ j ] + c [ k ] < x ) j ++ ; else k -- ; } } return false ; } private static void swap ( int x , int y ) { int temp = x ; x = y ; y = temp ; } private static void swap ( int [ ] x , int [ ] y ) { int [ ] temp = x ; x = y ; y = temp ; } public static void Main ( String [ ] args ) { int [ ] a = { 2 , 7 , 8 , 10 , 15 } ; int [ ] b = { 1 , 6 , 7 , 8 } ; int [ ] c = { 4 , 5 , 5 } ; int l1 = a . Length ; int l2 = b . Length ; int l3 = c . Length ; int x = 14 ; if ( existsTriplet ( a , b , c , x , l1 , l2 , l3 ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Arrange given numbers to form the smallest number | C # implementation for above approach ; Utility function to print the contents of an array ; A comparison function that return negative if ' AB ' is smaller than ' BA ' when we concatenate two numbers ' A ' and ' B ' For example , it will return negative value if we pass 12 and 24 as arguments . This function will be used during sort ; Convert first number to string format ; Convert second number to string format ; Check if ' AB ' is smaller or ' BA ' and return integer value ; Function to print the arrangement with the smallest value ; Sort using compare function which is defined above ; Print the sorted array ; Driver code
using System ; class GFG { public static void printArr ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] ) ; } public static int compare ( int num1 , int num2 ) { String A = num1 . ToString ( ) ; String B = num2 . ToString ( ) ; return ( A + B ) . CompareTo ( B + A ) ; } public static void printSmallest ( int N , int [ ] arr ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( compare ( arr [ i ] , arr [ j ] ) > 0 ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; } } } printArr ( arr , N ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 6 , 2 , 9 , 21 , 1 } ; int N = arr . Length ; printSmallest ( N , arr ) ; } }
Stable Selection Sort | C # program for modifying Selection Sort so that it becomes stable . ; Iterate through array elements ; Find minimum element from arr [ i ] to arr [ n - 1 ] . ; Move minimum element at current i . ; Driver code
using System ; class GFG { static void stableSelectionSort ( int [ ] a , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) { int min = i ; for ( int j = i + 1 ; j < n ; j ++ ) if ( a [ min ] > a [ j ] ) min = j ; int key = a [ min ] ; while ( min > i ) { a [ min ] = a [ min - 1 ] ; min -- ; } a [ i ] = key ; } } static void printArray ( int [ ] a , int n ) { for ( int i = 0 ; i < n ; i ++ ) Console . Write ( a [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } public static void Main ( ) { int [ ] a = { 4 , 5 , 3 , 2 , 4 , 1 } ; int n = a . Length ; stableSelectionSort ( a , n ) ; printArray ( a , n ) ; } }
Permute two arrays such that sum of every pair is greater or equal to K | C # program to check whether permutation of two arrays satisfy the condition a [ i ] + b [ i ] >= k . ; Check whether any permutation exists which satisfy the condition . ; Sort the array a [ ] in decreasing order . ; Sort the array b [ ] in increasing order . ; Checking condition on each index . ; Driver code
using System ; class GFG { static bool isPossible ( int [ ] a , int [ ] b , int n , int k ) { Array . Sort ( a ) ; Array . Reverse ( b ) ; for ( int i = 0 ; i < n ; i ++ ) if ( a [ i ] + b [ i ] < k ) return false ; return true ; } public static void Main ( ) { int [ ] a = { 2 , 1 , 3 } ; int [ ] b = { 7 , 8 , 9 } ; int k = 10 ; int n = a . Length ; if ( isPossible ( a , b , n , k ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Sort an array according to count of set bits | C # program to implement simple approach to sort an array according to count of set bits . ; Function to count setbits ; Function to sort By SetBitCount ; Iterate over all values and insert into multimap ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int setBitCount ( int num ) { int count = 0 ; while ( num != 0 ) { if ( ( num & 1 ) != 0 ) count ++ ; num >>= 1 ; } return count ; } static void sortBySetBitCount ( int [ ] arr , int n ) { List < Tuple < int , int > > count = new List < Tuple < int , int > > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { count . Add ( new Tuple < int , int > ( ( - 1 ) * setBitCount ( arr [ i ] ) , arr [ i ] ) ) ; } count . Sort ( ) ; foreach ( Tuple < int , int > i in count ) { Console . Write ( i . Item2 + " ▁ " ) ; } Console . WriteLine ( ) ; } static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 } ; int n = arr . Length ; sortBySetBitCount ( arr , n ) ; } }
Check if end of given Binary string can be reached by choosing jump value in between given range | C # program for the above approach ; Function to check if it is possible to reach the end of the binary string using the given jumps ; Stores the DP states ; Initial state ; Stores count of indices from which it is possible to reach index i ; Traverse the given string ; Update the values of pre accordingly ; If the jump size is out of the range [ L , R ] ; Return answer ; Driver Code
using System ; public class GFG { static int canReach ( String s , int L , int R ) { int [ ] dp = new int [ s . Length ] ; dp [ 0 ] = 1 ; int pre = 0 ; for ( int i = 1 ; i < s . Length ; i ++ ) { if ( i >= L ) { pre += dp [ i - L ] ; } if ( i > R ) { pre -= dp [ i - R - 1 ] ; } if ( pre > 0 && s [ i ] == '0' ) dp [ i ] = 1 ; else dp [ i ] = 0 ; } return dp [ s . Length - 1 ] ; } public static void Main ( ) { String S = "01101110" ; int L = 2 , R = 3 ; if ( canReach ( S , L , R ) == 1 ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Split an array into subarrays with maximum Bitwise XOR of their respective Bitwise OR values | C # program for the above approach ; Recursive function to find all the possible breaking of arrays into subarrays and find the maximum Bitwise XOR ; If the value of N is 0 ; Stores the result if the new group is formed with the first element as arr [ i ] ; Stores if the result if the arr [ i ] is included in the last group ; Returns the maximum of x and y ; Function to find the maximum possible Bitwise XOR of all possible values of the array after breaking the arrays into subarrays ; Return the result ; Driver code
using System ; class GFG { static int maxXORUtil ( int [ ] arr , int N , int xrr , int orr ) { if ( N == 0 ) return xrr ^ orr ; int x = maxXORUtil ( arr , N - 1 , xrr ^ orr , arr [ N - 1 ] ) ; int y = maxXORUtil ( arr , N - 1 , xrr , orr arr [ N - 1 ] ) ; return Math . Max ( x , y ) ; } static int maximumXOR ( int [ ] arr , int N ) { return maxXORUtil ( arr , N , 0 , 0 ) ; } static void Main ( ) { int [ ] arr = { 1 , 5 , 7 } ; int N = arr . Length ; Console . Write ( maximumXOR ( arr , N ) ) ; } }