codeparrot/xlcost-text-to-code huggingface dataset:
Find the array element from indices not divisible by K having largest composite product of digits | C # program to implement the above approach ; Function to check if a number is a composite number or not ; Corner cases ; Check if number is divisible by 2 or 3 ; Check if number is a multiple of any other prime number ; Function to calculate the product of digits of a number ; Stores the product of digits ; Extract digits of a number ; Calculate product of digits ; Function to check if the product of digits of a number is a composite number or not ; Stores product of digits ; If product of digits is equal to 1 ; If product of digits is not prime ; Function to find the number with largest composite product of digits from the indices not divisible by k from the given array ; Traverse the array ; If index is divisible by k ; Check if product of digits is a composite number or not ; Sort the products ; Driver Code
using System ; using System . Collections . Generic ; class GFG { class pair : IComparable < pair > { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } public int CompareTo ( pair p ) { return this . second - p . first ; } } static bool isComposite ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return false ; if ( n % 2 == 0 n % 3 == 0 ) return true ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return true ; return false ; } static int digitProduct ( int number ) { int product = 1 ; while ( number > 0 ) { product *= ( number % 10 ) ; number /= 10 ; } return product ; } static bool compositedigitProduct ( int num ) { int res = digitProduct ( num ) ; if ( res == 1 ) { return false ; } if ( isComposite ( res ) ) { return true ; } return false ; } static int largestCompositeDigitProduct ( int [ ] a , int n , int k ) { List < pair > pq = new List < pair > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( i % k ) == 0 ) { continue ; } if ( compositedigitProduct ( a [ i ] ) ) { int b = digitProduct ( a [ i ] ) ; pq . Add ( new pair ( b , a [ i ] ) ) ; } } pq . Sort ( ) ; return pq [ pq . Count - 1 ] . second ; } public static void Main ( String [ ] args ) { int [ ] arr = { 233 , 144 , 89 , 71 , 13 , 21 , 11 , 34 , 55 , 23 } ; int n = arr . Length ; int k = 3 ; int ans = largestCompositeDigitProduct ( arr , n , k ) ; Console . Write ( ans + " STRNEWLINE " ) ; } }
Split array into K | C # implementation for above approach ; Function to find the minimum sum of 2 nd smallest elements of each subset ; Sort the array ; Stores minimum sum of second elements of each subset ; Traverse first K 2 nd smallest elements ; Update their sum ; Print the sum ; Driver Code ; Given Array ; Given length of array ; Given subset lengths
using System ; class GFG { public static void findMinimum ( int [ ] arr , int N , int K ) { Array . Sort ( arr ) ; int ans = 0 ; for ( int i = 1 ; i < 2 * ( N / K ) ; i += 2 ) { ans += arr [ i ] ; } Console . WriteLine ( ans ) ; } public static void Main ( ) { int [ ] arr = { 11 , 20 , 5 , 7 , 8 , 14 , 2 , 17 , 16 , 10 } ; int N = arr . Length ; int K = 5 ; findMinimum ( arr , N , K ) ; } }
Find two non | C # program for the above approach ; Function to check if two non - intersecting subarrays with equal sum exists or not ; Sort the given array ; Traverse the array ; Check for duplicate elements ; If no duplicate element is present in the array ; Driver code ; Given array ; Size of array
using System ; class GFG { static void findSubarrays ( int [ ] arr , int N ) { Array . Sort ( arr ) ; int i = 0 ; for ( i = 0 ; i < N - 1 ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { Console . WriteLine ( " YES " ) ; return ; } } Console . WriteLine ( " NO " ) ; } public static void Main ( ) { int [ ] arr = { 4 , 3 , 0 , 1 , 2 , 0 } ; int N = arr . Length ; findSubarrays ( arr , N ) ; } }
Selection Sort VS Bubble Sort | C # program for the above approach ; Function for bubble sort ; Iterate from 1 to n - 1 ; Iterate from 0 to n - i - 1 ; Driver Code
using System ; public class GFG { static void Bubble_Sort ( int [ ] arr , int n ) { bool flag ; for ( int i = 1 ; i < n ; ++ i ) { flag = false ; for ( int j = 0 ; j <= ( n - i - 1 ) ; ++ j ) { if ( arr [ j ] > arr [ j + 1 ] ) { int temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; flag = true ; } } if ( flag == false ) break ; } } static public void Main ( ) { int n = 5 ; int [ ] arr = { 2 , 0 , 1 , 4 , 3 } ; Bubble_Sort ( arr , n ) ; Console . Write ( " The ▁ Sorted ▁ Array ▁ by ▁ using ▁ Bubble ▁ Sort ▁ is ▁ : ▁ " ) ; for ( int i = 0 ; i < n ; ++ i ) Console . Write ( arr [ i ] + " ▁ " ) ; } }
Print all array elements appearing more than N / K times | C # program to implement the above approach ; Function to print all array elements whose frequency is greater than N / K ; Sort the array , arr [ ] ; Traverse the array ; Stores frequency of arr [ i ] ; Traverse array elements which is equal to arr [ i ] ; Update cnt ; Update i ; If frequency of arr [ i ] is greater than ( N / K ) ; Driver Code
using System ; class GFG { static void NDivKWithFreq ( int [ ] arr , int N , int K ) { Array . Sort ( arr ) ; for ( int i = 0 ; i < N ; ) { int cnt = 1 ; while ( ( i + 1 ) < N && arr [ i ] == arr [ i + 1 ] ) { cnt ++ ; i ++ ; } if ( cnt > ( N / K ) ) { Console . Write ( arr [ i ] + " ▁ " ) ; } i ++ ; } } public static void Main ( ) { int [ ] arr = { 1 , 2 , 2 , 6 , 6 , 6 , 6 , 7 , 10 } ; int N = arr . Length ; int K = 4 ; NDivKWithFreq ( arr , N , K ) ; } }
Sort M elements of given circular array starting from index K | C # program for the above approach ; Function to print the circular array ; Print the array ; Function to sort m elements of diven circular array starting from index k ; Traverse M elements ; Iterate from index k to k + m - 1 ; Check if the next element in the circular array is less than the current element ; Swap current element with the next element ; Print the circular array ; Driver Code ; Function Call
using System ; class GFG { static void printCircularArray ( int [ ] arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } static void sortCircularArray ( int [ ] arr , int n , int k , int m ) { for ( int i = 0 ; i < m ; i ++ ) { for ( int j = k ; j < k + m - 1 ; j ++ ) { if ( arr [ j % n ] > arr [ ( j + 1 ) % n ] ) { int t = arr [ j % n ] ; arr [ j % n ] = arr [ ( j + 1 ) % n ] ; arr [ ( j + 1 ) % n ] = t ; } } } printCircularArray ( arr , n ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 4 , 1 , 6 , 5 , 3 } ; int K = 2 , M = 3 ; int N = arr . Length ; sortCircularArray ( arr , N , K , M ) ; } }
Split array into equal length subsets with maximum sum of Kth largest element of each subset | C # program to implement the above approach ; Function to find the maximum sum of Kth largest element of M equal length partition ; Stores sum of K_th largest element of equal length partitions ; If N is not divisible by M ; Stores length of each partition ; If K is greater than length of partition ; Sort array in descending porder ; Traverse the array ; Update maxSum ; Driver code
using System ; class GFG { static int maximumKthLargestsumPart ( int [ ] arr , int N , int M , int K ) { int maxSum = 0 ; if ( N % M != 0 ) return - 1 ; int sz = ( N / M ) ; if ( K > sz ) return - 1 ; Array . Sort ( arr ) ; Array . Reverse ( arr ) ; for ( int i = 1 ; i <= M ; i ++ ) { maxSum += arr [ i * K - 1 ] ; } return maxSum ; } static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 6 } ; int M = 2 ; int K = 1 ; int N = arr . Length ; Console . WriteLine ( maximumKthLargestsumPart ( arr , N , M , K ) ) ; } }
Minimize difference between maximum and minimum array elements by exactly K removals | C # program for the above approach ; Function to minimize the difference of the maximum and minimum array elements by removing K elements ; Base Condition ; Sort the array ; Initialize left and right pointers ; Iterate for K times ; Removing right element to reduce the difference ; Removing the left element to reduce the difference ; Print the minimum difference ; Driver Code ; Function Call
using System ; class GFG { static void minimumRange ( int [ ] arr , int N , int K ) { if ( K >= N ) { Console . Write ( 0 ) ; return ; } Array . Sort ( arr ) ; int left = 0 , right = N - 1 , i ; for ( i = 0 ; i < K ; i ++ ) { if ( arr [ right - 1 ] - arr [ left ] < arr [ right ] - arr [ left + 1 ] ) right -- ; else left ++ ; } Console . Write ( arr [ right ] - arr [ left ] ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 5 , 10 , 12 , 14 , 21 , 54 , 61 } ; int N = arr . Length ; int K = 4 ; minimumRange ( arr , N , K ) ; } }
Split array into K subsets to maximize sum of their second largest elements | C # program for the above approach ; Function to split array into K subsets having maximum sum of their second maximum elements ; Sort the array ; Stores the maximum possible sum of second maximums ; Add second maximum of current subset ; Proceed to the second maximum of next subset ; Print the maximum sum obtained ; Drive Code ; Given array [ ] arr ; Size of array ; Function Call
using System ; class GFG { static void splitArray ( int [ ] arr , int n , int K ) { Array . Sort ( arr ) ; int i = n - 1 ; int result = 0 ; while ( K -- != 0 ) { result += arr [ i - 1 ] ; i -= 2 ; } Console . Write ( result ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 1 , 5 , 1 , 3 } ; int N = arr . Length ; int K = 2 ; splitArray ( arr , N , K ) ; } }
Count subsequences for every array element in which they are the maximum | C # program for the above approach ; Function to merge the subarrays arr [ l . . m ] and arr [ m + 1 , . . r ] based on indices [ ] ; If a [ indices [ l ] ] is less than a [ indices [ j ] ] , add indice [ l ] to temp ; Else add indices [ j ] ; Add remaining elements ; Add remainging elements ; Recursive function to divide the array into to parts ; Recursive call for elements before mid ; Recursive call for elements after mid ; Merge the two sorted arrays ; Function to find the number of subsequences for each element ; Sorting the indices according to array [ ] arr ; Array to store output numbers ; Initialize subseq ; B [ i ] is 2 ^ i ; Doubling the subsequences ; Print the readonly output , array [ ] B ; Driver Code ; Given array ; Given length ; Function call
using System ; class GFG { static void merge ( int [ ] indices , int [ ] a , int l , int mid , int r ) { int [ ] temp_ind = new int [ r - l + 1 ] ; int j = mid + 1 ; int i = 0 , temp_l = l , k ; while ( l <= mid && j <= r ) { if ( a [ indices [ l ] ] < a [ indices [ j ] ] ) temp_ind [ i ++ ] = indices [ l ++ ] ; else temp_ind [ i ++ ] = indices [ j ++ ] ; } while ( l <= mid ) temp_ind [ i ++ ] = indices [ l ++ ] ; while ( j <= r ) temp_ind [ i ++ ] = indices [ j ++ ] ; for ( k = 0 ; k < i ; k ++ ) indices [ temp_l ++ ] = temp_ind [ k ] ; } static void divide ( int [ ] indices , int [ ] a , int l , int r ) { if ( l >= r ) return ; int mid = l / 2 + r / 2 ; divide ( indices , a , l , mid ) ; divide ( indices , a , mid + 1 , r ) ; merge ( indices , a , l , mid , r ) ; } static void noOfSubsequences ( int [ ] arr , int N ) { int [ ] indices = new int [ N ] ; int i ; for ( i = 0 ; i < N ; i ++ ) indices [ i ] = i ; divide ( indices , arr , 0 , N - 1 ) ; int [ ] B = new int [ N ] ; int subseq = 1 ; for ( i = 0 ; i < N ; i ++ ) { B [ indices [ i ] ] = subseq ; subseq *= 2 ; } for ( i = 0 ; i < N ; i ++ ) Console . Write ( B [ i ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 3 , 1 } ; int N = arr . Length ; noOfSubsequences ( arr , N ) ; } }
Find the order of execution of given N processes in Round Robin Scheduling | C # program for the above approach ; Function to sort the array order [ ] on the basis of the array freq [ ] ; If order [ i ] th is less than order [ temp ] th process ; Otherwise ; Add the left half to tempOrder [ ] ; Add right half to tempOrder [ ] ; Copy the tempOrder [ ] array to order [ ] array ; Utility function to sort the array order [ ] on the basis of freq [ ] ; Base Case ; Divide array into 2 parts ; Sort the left array ; Sort the right array ; Merge the sorted arrays ; Function to find the order of processes in which execution occurs ; Store the frequency ; Find elements in array freq [ ] ; Store the order of completion of processes ; Initialize order [ i ] as i ; Function Call to find the order of execution ; Print order of completion of processes ; Driver Code ; Burst Time of the processes ; Quantum Time ; Function Call
using System ; class GFG { static void merge ( int [ ] order , int [ ] freq , int i , int mid , int j ) { int [ ] tempOrder = new int [ j - i + 1 ] ; int temp = mid + 1 , index = - 1 ; while ( i <= mid && temp <= j ) { if ( freq [ order [ i ] ] <= freq [ order [ temp ] ] ) { tempOrder [ ++ index ] = order [ i ++ ] ; } else { tempOrder [ ++ index ] = order [ temp ++ ] ; } } while ( i <= mid ) { tempOrder [ ++ index ] = order [ i ++ ] ; } while ( temp <= j ) { tempOrder [ ++ index ] = order [ temp ++ ] ; } int ind = index ; for ( index = ind ; index >= 0 ; index -- ) { order [ j -- ] = tempOrder [ index ] ; } } static void divide ( int [ ] order , int [ ] freq , int i , int j ) { if ( i >= j ) return ; int mid = i / 2 + j / 2 ; divide ( order , freq , i , mid ) ; divide ( order , freq , mid + 1 , j ) ; merge ( order , freq , i , mid , j ) ; } static void orderProcesses ( int [ ] A , int N , int q ) { int i = 0 ; int [ ] freq = new int [ N ] ; for ( i = 0 ; i < N ; i ++ ) { freq [ i ] = ( A [ i ] / q ) ; if ( A [ i ] % q > 0 ) freq [ i ] += 1 ; } int [ ] order = new int [ 4 ] ; for ( i = 0 ; i < N ; i ++ ) { order [ i ] = i ; } divide ( order , freq , 0 , N - 1 ) ; for ( i = 0 ; i < N ; i ++ ) { Console . Write ( order [ i ] + " ▁ " ) ; } } public static void Main ( ) { int [ ] arr = { 3 , 7 , 4 } ; int Q = 3 ; int N = arr . Length ; orderProcesses ( arr , N , Q ) ; } }
Maximize cost to empty given array by repetitively removing K array elements | C # program for the above approach ; Function to find the maximum cost to remove all array elements ; Stores maximum cost to remove array elements ; Sort array in ascending order ; Traverse the array ; Update maxCost ; Drive Code
using System ; class GFG { static int maxCostToRemove ( int [ ] arr , int N , int K ) { int maxCost = 0 ; Array . Sort ( arr ) ; for ( int i = 0 ; i < N ; i += K ) { maxCost += arr [ i + 1 ] ; } return maxCost ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 4 , 1 , 5 , 1 , 5 , 3 } ; int N = arr . Length ; int K = 4 ; Console . Write ( maxCostToRemove ( arr , N , K ) ) ; } }
Print all numbers up to N in words in lexicographical order | C # program for the above approach ; Function to convert a number to words ; Stores the digits ; Base cases ; Stores strings of unit place ; Stores strings for corner cases ; Stores strings for ten 's place digits ; Stores strings for powers of 10 ; If given number contains a single digit ; Iterate over all the digits ; Represent first 2 digits in words ; Represent last 2 digits in words ; Explicitly handle corner cases [ 10 , 19 ] ; Explicitly handle corner case 20 ; For rest of the two digit numbers i . e . , 21 to 99 ; Function to print all the numbers up to n in lexicographical order ; Convert all numbers in words ; Sort all strings ; Print answer ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static String convert_to_words ( int n ) { char [ ] num = String . Join ( " " , n ) . ToCharArray ( ) ; int len = num . Length ; String ans = " " ; if ( len == 0 ) { ans += " Empty ▁ String " ; return ans ; } String [ ] single_digits = new String [ ] { " zero " , " one " , " two " , " three " , " four " , " five " , " six " , " seven " , " eight " , " nine " } ; String [ ] two_digits = new String [ ] { " " , " ten " , " eleven " , " twelve " , " thirteen " , " fourteen " , " fifteen " , " sixteen " , " seventeen " , " eighteen " , " nineteen " } ; String [ ] tens_multiple = new String [ ] { " " , " " , " twenty " , " thirty " , " forty " , " fifty " , " sixty " , " seventy " , " eighty " , " ninety " } ; String [ ] tens_power = new String [ ] { " hundred " , " thousand " } ; if ( len == 1 ) { ans += single_digits [ num [ 0 ] - '0' ] ; return ans ; } int x = 0 ; while ( x < num . Length ) { if ( len >= 3 ) { if ( num [ x ] - '0' != 0 ) { ans += single_digits [ num [ x ] - '0' ] ; ans += " ▁ " ; ans += tens_power [ len - 3 ] ; ans += " ▁ " ; } -- len ; } else { if ( num [ x ] - '0' == 1 ) { int sum = num [ x ] - '0' + num [ x ] - '0' ; ans += two_digits [ sum ] ; return ans ; } else if ( num [ x ] - '0' == 2 && num [ x + 1 ] - '0' == 0 ) { ans += " twenty " ; return ans ; } else { int i = ( num [ x ] - '0' ) ; if ( i > 0 ) { ans += tens_multiple [ i ] ; ans += " ▁ " ; } else ans += " " ; ++ x ; if ( num [ x ] - '0' != 0 ) ans += single_digits [ num [ x ] - '0' ] ; } } ++ x ; } return " " ; } static void lexNumbers ( int n ) { List < String > s = new List < String > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) { s . Add ( convert_to_words ( i ) ) ; } s . Sort ( ) ; List < String > ans = new List < String > ( ) ; for ( int i = 0 ; i < n ; i ++ ) ans . Add ( s [ i ] ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) Console . Write ( ans [ i ] + " , ▁ " ) ; Console . Write ( ans [ n - 1 ] ) ; } public static void Main ( String [ ] args ) { int n = 5 ; lexNumbers ( n ) ; } }
Minimize cost to convert all array elements to 0 | C # program for the above approach ; Function to calculate the minimum cost of converting all array elements to 0 s ; Stores subarrays of 0 s only ; Traverse the array ; If consecutive 0 s occur ; Increment if needed ; Push the current length of consecutive 0 s in a vector ; Update lengths as 0 ; Sorting List ; Stores the number of subarrays consisting of 1 s ; Traverse the array ; If current element is 1 ; Otherwise ; Increment count of consecutive ones ; Stores the minimum cost ; Traverse the array ; First element ; Traverse the subarray sizes ; Update cost ; Cost of performing X and Y operations ; Find the minimum cost ; Print the minimum cost ; Driver code ; Function Call
using System ; using System . Collections . Generic ; class GFG { public static void minimumCost ( int [ ] binary , int n , int a , int b ) { List < int > groupOfZeros = new List < int > ( ) ; int len = 0 , i = 0 ; bool increment_need = true ; while ( i < n ) { increment_need = true ; while ( i < n && binary [ i ] == 0 ) { len ++ ; i ++ ; increment_need = false ; } if ( increment_need == true ) { i ++ ; } if ( len != 0 ) { groupOfZeros . Add ( len ) ; } len = 0 ; } groupOfZeros . Sort ( ) ; i = 0 ; bool found_ones = false ; int NumOfOnes = 0 ; while ( i < n ) { found_ones = false ; while ( i < n && binary [ i ] == 1 ) { i ++ ; found_ones = true ; } if ( found_ones == false ) i ++ ; else NumOfOnes ++ ; } int ans = int . MaxValue ; for ( int i1 = 0 ; i1 < n ; i1 ++ ) { int curr = 0 , totalOnes = NumOfOnes ; if ( i1 == 0 ) { curr = totalOnes * a ; } else { int mark = i1 , num_of_changes = 0 ; foreach ( int x in groupOfZeros ) { if ( mark >= x ) { totalOnes -- ; mark -= x ; num_of_changes += x ; } else { break ; } } curr = ( num_of_changes * b ) + ( totalOnes * a ) ; } ans = Math . Min ( ans , curr ) ; } Console . WriteLine ( ans ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 1 , 0 , 1 , 1 } ; int N = 6 ; int X = 10 , Y = 4 ; minimumCost ( arr , N , X , Y ) ; } }
Reduce array to longest sorted array possible by removing either half of given array in each operation | C # program to implement the above approach ; Function to check if the subarray arr [ i . . j ] is a sorted subarray or not ; Traverse all elements of the subarray arr [ i ... j ] ; If the previous element of the subarray exceeds current element ; Return 0 ; Return 1 ; Recursively partition the array into two equal halves ; If atmost one element is left in the subarray arr [ i . . j ] ; Checks if subarray arr [ i . . j ] is a sorted subarray or not ; If the subarray arr [ i ... j ] is a sorted subarray ; Stores middle element of the subarray arr [ i . . j ] ; Recursively partition the current subarray arr [ i . . j ] into equal halves ; Driver Code
using System ; class GFG { static int isSortedparitions ( int [ ] arr , int i , int j ) { for ( int k = i + 1 ; k <= j ; k ++ ) { if ( arr [ k ] < arr [ k - 1 ] ) { return 0 ; } } return 1 ; } static int partitionsArr ( int [ ] arr , int i , int j ) { if ( i >= j ) return 1 ; int flag = ( int ) isSortedparitions ( arr , i , j ) ; if ( flag != 0 ) { return ( j - i + 1 ) ; } int mid = ( i + j ) / 2 ; int X = partitionsArr ( arr , i , mid ) ; int Y = partitionsArr ( arr , mid + 1 , j ) ; return Math . Max ( X , Y ) ; } public static void Main ( ) { int [ ] arr = { 11 , 12 , 1 , 2 , 13 , 14 , 3 , 4 } ; int N = arr . Length ; Console . Write ( partitionsArr ( arr , 0 , N - 1 ) ) ; } }
Check if two sorted arrays can be merged to form a sorted array with no adjacent pair from the same array | C # program to implement the above approach ; Function to check if it is possible to merge the two given arrays with given conditions ; Stores index of the array A [ ] ; Stores index of the array B [ ] ; Check if the previous element are from the array A [ ] or from the array B [ ] ; Check if it is possible to merge the two given sorted arrays with given conditions ; Traverse both the arrays ; If A [ i ] is less than B [ j ] and previous element are not from A [ ] ; Update prev ; Update i ; If B [ j ] is less than A [ i ] and previous element are not from B [ ] ; Update prev ; Update j ; If A [ i ] equal to B [ j ] ; If previous element are not from B [ ] ; Update prev ; Update j ; If previous element is not from A [ ] ; Update prev ; Update i ; If it is not possible to merge two sorted arrays with given conditions ; Update flag ; Driver Code
using System ; class GFG { static bool checkIfPossibleMerge ( int [ ] A , int [ ] B , int N ) { int i = 0 ; int j = 0 ; int prev = - 1 ; bool flag = true ; while ( i < N && j < N ) { if ( A [ i ] < B [ j ] && prev != 0 ) { prev = 0 ; i ++ ; } else if ( B [ j ] < A [ i ] && prev != 1 ) { prev = 1 ; j ++ ; } else if ( A [ i ] == B [ j ] ) { if ( prev != 1 ) { prev = 1 ; j ++ ; } else { prev = 0 ; i ++ ; } } else { flag = false ; break ; } } return flag ; } public static void Main ( ) { int [ ] A = { 3 , 5 , 8 } ; int [ ] B = { 2 , 4 , 6 } ; int N = A . Length ; if ( checkIfPossibleMerge ( A , B , N ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }